Skip to content

Commit

Permalink
Merge pull request #3 from jubianchi/master
Browse files Browse the repository at this point in the history
Use atoum tools to write better tests
  • Loading branch information
tejerka committed Jan 14, 2016
2 parents 7066fa5 + 9308ab5 commit efb26e5
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 118 deletions.
3 changes: 3 additions & 0 deletions .atoum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

$runner->addTestsFromDirectory(__DIR__ . '/tests/units');
3 changes: 3 additions & 0 deletions .bootstrap.atoum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

require_once __DIR__ . '/vendor/autoload.php';
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ php:
script:
- composer install
- mkdir -p build/logs
- php vendor/atoum/atoum/bin/atoum -c travis-coverage.php -d tests/units/
- php vendor/atoum/atoum/bin/atoum -c travis-coverage.php

after_script:
- php vendor/bin/coveralls -v
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"aws/aws-sdk-php": ">=2.7"
},
"require-dev": {
"atoum/atoum": "dev-master",
"atoum/atoum": "~2",
"satooshi/php-coveralls": "dev-master"
},
"autoload": {
Expand Down
51 changes: 26 additions & 25 deletions tests/units/Adapter/FileAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

namespace ReputationVIP\QueueClient\tests\units\Adapter;

require_once __DIR__ . '/../../../vendor/autoload.php';

use ArrayIterator;
use mageekguy\atoum;
use ReputationVIP\QueueClient\PriorityHandler\ThreeLevelPriorityHandler;
use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
use ReputationVIP\QueueClient\Utils\LockHandlerFactory;

class MockIOExceptionInterface extends \Exception implements IOExceptionInterface {

Expand All @@ -19,28 +20,28 @@ public function getPath()

class FileAdapter extends atoum\test
{
public function testFileAdapter__constructWithFilesystemError()
public function testFileAdapterClass()
{
$mockFs = new \mock\Symfony\Component\Filesystem\Filesystem;
$mockFinder = new \mock\Symfony\Component\Finder\Finder;
$mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory;

$this->exception(function () use($mockFs, $mockFinder, $mockLockHandlerFactory) {
new \ReputationVIP\QueueClient\Adapter\FileAdapter('', null, $mockFs, $mockFinder, $mockLockHandlerFactory);
});
$mockFs->getMockController()->mkdir = function($repository) {
throw new MockIOExceptionInterface('');
};
$mockFs->getMockController()->exists = false;
$this->exception(function () use($mockFs, $mockFinder, $mockLockHandlerFactory) {
new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory);
});
$this->testedClass->implements('\ReputationVIP\QueueClient\Adapter\AdapterInterface');
}

public function testFileAdapter__construct()
{
$this->given()
->class(new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface');
$this->object($this->newTestedInstance('/tmp/test/'));
}

public function testFileAdapter__constructWithFilesystemError(Filesystem $fs, Finder $finder, LockHandlerFactory $lockHandlerFactory)
{
$this->exception(function () use($fs, $finder, $lockHandlerFactory) {
$this->newTestedInstance('', null, $fs, $finder, $lockHandlerFactory);
});

$this->calling($fs)->mkdir->throw = new MockIOExceptionInterface;
$this->calling($fs)->exists = false;

$this->exception(function () use($fs, $finder, $lockHandlerFactory) {
$this->newTestedInstance('/tmp/test/', null, $fs, $finder, $lockHandlerFactory);
});
}

public function testFileAdapterDeleteQueue()
Expand All @@ -49,9 +50,9 @@ public function testFileAdapterDeleteQueue()
$mockFinder = new \mock\Symfony\Component\Finder\Finder;
$mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory;

$mockFs->getMockController()->exists = true;
$this->calling($mockFs)->exists = true;
$FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory);
$mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) {
$this->calling($mockLockHandlerFactory)->getLockHandler = function($repository) {
$mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository);
$mockLockHandler->getMockController()->lock = true;
return $mockLockHandler;
Expand All @@ -78,9 +79,9 @@ public function testFileAdapterDeleteQueueWithNoQueueFile()
$mockFinder = new \mock\Symfony\Component\Finder\Finder;
$mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory;

$mockFs->getMockController()->exists = false;
$this->calling($mockFs)->exists = false;
$FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory);
$mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) {
$this->calling($mockLockHandlerFactory)->getLockHandler = function($repository) {
$mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository);
$mockLockHandler->getMockController()->lock = true;
return $mockLockHandler;
Expand All @@ -97,8 +98,8 @@ public function testFileAdapterDeleteQueueWithLockFailed()
$mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory;

$FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory);
$mockFs->getMockController()->exists = true;
$mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) {
$this->calling($mockFs)->exists = true;
$this->calling($mockLockHandlerFactory)->getLockHandler = function($repository) {
$mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository);
$mockLockHandler->getMockController()->lock = false;
return $mockLockHandler;
Expand Down
58 changes: 31 additions & 27 deletions tests/units/Adapter/MemoryAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@

namespace ReputationVIP\QueueClient\tests\units\Adapter;

require_once __DIR__ . '/../../../vendor/autoload.php';

use mageekguy\atoum;
use ReputationVIP\QueueClient\PriorityHandler\ThreeLevelPriorityHandler;

class MemoryAdapter extends atoum\test
{
public function testMemoryAdapterCreateQueue()
{
$MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter();

$this->given($MemoryAdapter)
->class($MemoryAdapter->createQueue('testQueue'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface');
$this->given($this->newTestedInstance)
->object($this->testedInstance->createQueue('testQueue'))->isTestedInstance()
;
}

public function testMemoryAdapterCreateQueueWithEmptyQueueName()
Expand All @@ -37,39 +34,46 @@ public function testMemoryAdapterCreateQueueWithQueueNameSpace()

public function testMemoryAdapterCreateQueueWithQueueExists()
{
$MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter();

$MemoryAdapter->createQueue('testQueue');
$this->exception(function() use($MemoryAdapter) {
$MemoryAdapter->createQueue('testQueue');
});
$this
->given($this->newTestedInstance)
->when($this->testedInstance->createQueue('testQueue'))
->then
->exception(function() {
$this->testedInstance->createQueue('testQueue');
})
;
}

public function testMemoryAdapterDeleteQueue()
{
$MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter();

$MemoryAdapter->createQueue('testQueue');
$this->given($MemoryAdapter)
->class($MemoryAdapter->deleteQueue('testQueue'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface');
$this
->given($this->newTestedInstance)
->when($this->testedInstance->createQueue('testQueue'))
->then
->object($this->testedInstance->deleteQueue('testQueue'))->isTestedInstance()
;
}

public function testMemoryAdapterDeleteQueueWithEmptyQueueName()
{
$MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter();

$this->exception(function() use($MemoryAdapter) {
$MemoryAdapter->deleteQueue('');
});
$this
->given($this->newTestedInstance)
->then
->exception(function() {
$this->testedInstance->deleteQueue('');
})
;
}

public function testMemoryAdapterDeleteQueueWithQueueDoesNotExists()
{
$MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter();

$this->exception(function() use($MemoryAdapter) {
$MemoryAdapter->deleteQueue('testQueue');
});
$this
->given($this->newTestedInstance)
->then
->exception(function() {
$this->testedInstance->deleteQueue('testQueue');
})
;
}

public function testMemoryAdapterRenameQueue()
Expand Down
2 changes: 0 additions & 2 deletions tests/units/Adapter/NullAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace ReputationVIP\QueueClient\tests\units\Adapter;

require_once __DIR__ . '/../../../vendor/autoload.php';

use mageekguy\atoum;

class NullAdapter extends atoum\test
Expand Down
2 changes: 0 additions & 2 deletions tests/units/Adapter/SQSAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace ReputationVIP\QueueClient\tests\units\Adapter;

require_once __DIR__ . '/../../../vendor/autoload.php';

use mageekguy\atoum;
use ReputationVIP\QueueClient\PriorityHandler\ThreeLevelPriorityHandler;

Expand Down
2 changes: 0 additions & 2 deletions tests/units/PriorityHandler/StandardPriorityHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace ReputationVIP\QueueClient\tests\units\PriorityHandler;

require_once __DIR__ . '/../../../vendor/autoload.php';

use mageekguy\atoum;

class StandardPriorityHandler extends atoum\test
Expand Down
Loading

0 comments on commit efb26e5

Please sign in to comment.