diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
new file mode 100644
index 0000000..aacd0e6
--- /dev/null
+++ b/.github/workflows/tests.yml
@@ -0,0 +1,37 @@
+name: Tests
+
+on:
+ pull_request:
+ push:
+ branches:
+ - master
+
+concurrency:
+ group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
+ cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}
+
+jobs:
+
+ tests:
+ runs-on: ubuntu-24.04
+ strategy:
+ matrix:
+ php-versions: [ '8.2', '8.3', '8.4' ]
+ fail-fast: false
+ steps:
+ - uses: actions/checkout@v4
+
+ - name: Setup PHP, with composer and extensions
+ uses: shivammathur/setup-php@v2
+ with:
+ php-version: ${{ matrix.php-versions }}
+ coverage: none
+
+ - name: Composer install
+ run: composer install --no-scripts --no-interaction --prefer-dist -oa
+
+ - name: Run Phpunit
+ run: ./vendor/bin/phpunit
+
+ - name: Run PHPStan
+ run: ./vendor/bin/phpstan analyse src
diff --git a/.gitignore b/.gitignore
index 821f911..5f01bb9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,4 @@
composer.lock
composer.phar
vendor/
+.phpunit.result.cache
diff --git a/composer.json b/composer.json
index 808c493..6aa3af7 100644
--- a/composer.json
+++ b/composer.json
@@ -26,11 +26,14 @@
},
"require": {
"php": ">=8.2",
- "doctrine/annotations": "~2.0",
- "openclassrooms/cache": "^v1.1.0"
+ "doctrine/annotations": "^1.0|~2.0",
+ "psr/log": "^2.0|^3.0",
+ "psr/cache": "^2.0|^3.0"
},
"require-dev": {
- "phpunit/phpunit": "^9.6.20"
+ "phpunit/phpunit": "^11.0",
+ "phpstan/phpstan": "^2.1",
+ "symfony/cache": "^5.4|^6.4|^7.0"
},
"extra": {
"branch-alias": {
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 30445d7..942a067 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -1,26 +1,18 @@
-
-
-
+
-
- ./tests/
+
+ tests/
-
-
- ./src
-
-
-
+
+
+ src/
+
+
+
+
+
diff --git a/src/OpenClassrooms/UseCase/Application/Services/Event/Exceptions/InvalidEventNameException.php b/src/OpenClassrooms/UseCase/Application/Services/Event/Exceptions/InvalidEventNameException.php
index bcd8681..0b12efd 100644
--- a/src/OpenClassrooms/UseCase/Application/Services/Event/Exceptions/InvalidEventNameException.php
+++ b/src/OpenClassrooms/UseCase/Application/Services/Event/Exceptions/InvalidEventNameException.php
@@ -2,8 +2,6 @@
namespace OpenClassrooms\UseCase\Application\Services\Event\Exceptions;
-use Exception;
-
/**
* @author Romain Kuzniak
*/
diff --git a/src/OpenClassrooms/UseCase/Application/Services/Proxy/Strategies/Impl/Cache/CacheProxyStrategy.php b/src/OpenClassrooms/UseCase/Application/Services/Proxy/Strategies/Impl/Cache/CacheProxyStrategy.php
index 5a01fe1..e1c6a0d 100644
--- a/src/OpenClassrooms/UseCase/Application/Services/Proxy/Strategies/Impl/Cache/CacheProxyStrategy.php
+++ b/src/OpenClassrooms/UseCase/Application/Services/Proxy/Strategies/Impl/Cache/CacheProxyStrategy.php
@@ -2,7 +2,6 @@
namespace OpenClassrooms\UseCase\Application\Services\Proxy\Strategies\Impl\Cache;
-use OpenClassrooms\Cache\Cache\Cache;
use OpenClassrooms\UseCase\Application\Services\Proxy\Strategies\Impl\DTO\ProxyStrategyResponseDTO;
use OpenClassrooms\UseCase\Application\Services\Proxy\Strategies\Requestors\Cache\CacheProxyStrategyRequest;
use OpenClassrooms\UseCase\Application\Services\Proxy\Strategies\Requestors\PostExecuteProxyStrategy;
@@ -10,27 +9,23 @@
use OpenClassrooms\UseCase\Application\Services\Proxy\Strategies\Requestors\ProxyStrategy;
use OpenClassrooms\UseCase\Application\Services\Proxy\Strategies\Requestors\ProxyStrategyRequest;
use OpenClassrooms\UseCase\Application\Services\Proxy\Strategies\Responders\ProxyStrategyResponse;
+use Psr\Cache\CacheItemInterface;
+use Psr\Cache\CacheItemPoolInterface;
/**
* @author Romain Kuzniak
*/
class CacheProxyStrategy implements PreExecuteProxyStrategy, PostExecuteProxyStrategy
{
-
- /**
- * @var mixed
- */
- private $data;
-
/**
- * @var Cache
+ * @var CacheItemPoolInterface
*/
private $cache;
/**
* @var bool
*/
- private $postExecute = true;
+ private $postExecute;
/**
* @return string
@@ -46,28 +41,14 @@ public function getType()
public function preExecute(ProxyStrategyRequest $proxyStrategyRequest)
{
/** @var CacheProxyStrategyRequest $proxyStrategyRequest */
- $this->data = $this->cache->fetchWithNamespace(
+ $item = $this->fetchWithNamespace(
$proxyStrategyRequest->getId(),
$proxyStrategyRequest->getNamespaceId()
);
- if ($this->responseIsInCache()) {
- $stopExecution = true;
- $this->postExecute = false;
- } else {
- $stopExecution = false;
- }
- $response = new ProxyStrategyResponseDTO($this->data, $stopExecution);
-
- return $response;
- }
+ $this->postExecute = !$item->isHit();
- /**
- * @return bool
- */
- private function responseIsInCache()
- {
- return $this->data;
+ return new ProxyStrategyResponseDTO($item->get(), $item->isHit());
}
/**
@@ -76,17 +57,51 @@ private function responseIsInCache()
public function postExecute(ProxyStrategyRequest $proxyStrategyRequest)
{
/** @var CacheProxyStrategyRequest $proxyStrategyRequest */
- $saved = $this->cache->saveWithNamespace(
+ $item = $this->saveWithNamespace(
$proxyStrategyRequest->getId(),
$proxyStrategyRequest->getData(),
$proxyStrategyRequest->getNamespaceId(),
$proxyStrategyRequest->getLifeTime()
);
- $response = new ProxyStrategyResponseDTO($saved, false);
- return $response;
+ return new ProxyStrategyResponseDTO($item->get(), false);
}
+ private function fetchWithNamespace(string $id, string $namespace = null): CacheItemInterface
+ {
+ if ($namespace !== null) {
+ $namespaceId = $this->cache->getItem($namespace);
+
+ $id = ((string) $namespaceId->get()) . $id;
+ }
+
+ return $this->cache->getItem($id);
+ }
+
+ private function saveWithNamespace(string $id, mixed $data, string $namespace = null, int $lifetime = null): CacheItemInterface
+ {
+ if ($namespace !== null) {
+ $namespaceId = $this->cache->getItem($namespace);
+
+ if (!$namespaceId->isHit()) {
+ $namespaceId->set($namespace . '_' . random_int(0, 10000));
+ $namespaceId->expiresAfter(604800); // 7 days
+
+ $this->cache->save($namespaceId);
+ }
+
+ $id = ((string) $namespaceId->get()) . $id;
+ }
+
+ $item = $this->cache->getItem($id);
+ $item->set($data)->expiresAfter($lifetime);
+
+ $this->cache->save($item);
+
+ return $item;
+ }
+
+
/**
* @return boolean
*/
@@ -95,7 +110,7 @@ public function isPostExecute()
return $this->postExecute;
}
- public function setCache(Cache $cache)
+ public function setCache(CacheItemPoolInterface $cache)
{
$this->cache = $cache;
}
diff --git a/src/OpenClassrooms/UseCase/Application/Services/Proxy/Strategies/Impl/CacheProxyStrategyBagImpl.php b/src/OpenClassrooms/UseCase/Application/Services/Proxy/Strategies/Impl/CacheProxyStrategyBagImpl.php
index dfca0dd..20958f2 100644
--- a/src/OpenClassrooms/UseCase/Application/Services/Proxy/Strategies/Impl/CacheProxyStrategyBagImpl.php
+++ b/src/OpenClassrooms/UseCase/Application/Services/Proxy/Strategies/Impl/CacheProxyStrategyBagImpl.php
@@ -28,8 +28,6 @@ class CacheProxyStrategyBagImpl extends ProxyStrategyBag
public function isPostExecute()
{
- /** @var $this ->proxyStrategy */
-
return $this->proxyStrategy->isPostExecute();
}
}
diff --git a/src/OpenClassrooms/UseCase/Application/Services/Proxy/Strategies/Impl/Transaction/TransactionProxyStrategy.php b/src/OpenClassrooms/UseCase/Application/Services/Proxy/Strategies/Impl/Transaction/TransactionProxyStrategy.php
index 0cb4a55..f0e3b97 100644
--- a/src/OpenClassrooms/UseCase/Application/Services/Proxy/Strategies/Impl/Transaction/TransactionProxyStrategy.php
+++ b/src/OpenClassrooms/UseCase/Application/Services/Proxy/Strategies/Impl/Transaction/TransactionProxyStrategy.php
@@ -45,7 +45,9 @@ public function preExecute(ProxyStrategyRequest $proxyStrategyRequest)
*/
public function postExecute(ProxyStrategyRequest $proxyStrategyRequest)
{
- return $this->transaction->commit();
+ $this->transaction->commit();
+
+ return new ProxyStrategyResponseDTO();
}
/**
@@ -54,8 +56,10 @@ public function postExecute(ProxyStrategyRequest $proxyStrategyRequest)
public function onException(ProxyStrategyRequest $proxyStrategyRequest)
{
if ($this->transaction->isTransactionActive()) {
- return $this->transaction->rollBack();
+ $this->transaction->rollBack();
}
+
+ return new ProxyStrategyResponseDTO();
}
public function setTransaction(Transaction $transaction)
diff --git a/src/OpenClassrooms/UseCase/Application/Services/Proxy/Strategies/Requestors/OnExceptionProxyStrategy.php b/src/OpenClassrooms/UseCase/Application/Services/Proxy/Strategies/Requestors/OnExceptionProxyStrategy.php
index 58c418b..c6e2ad0 100644
--- a/src/OpenClassrooms/UseCase/Application/Services/Proxy/Strategies/Requestors/OnExceptionProxyStrategy.php
+++ b/src/OpenClassrooms/UseCase/Application/Services/Proxy/Strategies/Requestors/OnExceptionProxyStrategy.php
@@ -10,7 +10,7 @@
interface OnExceptionProxyStrategy extends ProxyStrategy
{
/**
- * @return ProxyStrategyResponse
+ * @return ?bool
*/
public function onException(ProxyStrategyRequest $proxyStrategyRequest);
}
diff --git a/src/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/UseCaseProxyBuilder.php b/src/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/UseCaseProxyBuilder.php
index 05c4d4a..b58c02b 100644
--- a/src/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/UseCaseProxyBuilder.php
+++ b/src/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/UseCaseProxyBuilder.php
@@ -3,7 +3,6 @@
namespace OpenClassrooms\UseCase\Application\Services\Proxy\UseCases;
use Doctrine\Common\Annotations\Reader;
-use OpenClassrooms\Cache\Cache\Cache;
use OpenClassrooms\UseCase\Application\Services\Event\EventFactory;
use OpenClassrooms\UseCase\Application\Services\Event\EventSender;
use OpenClassrooms\UseCase\Application\Services\Proxy\Strategies\Impl\Cache\CacheProxyStrategy;
@@ -28,6 +27,7 @@
use OpenClassrooms\UseCase\Application\Services\Security\Security;
use OpenClassrooms\UseCase\Application\Services\Transaction\Transaction;
use OpenClassrooms\UseCase\BusinessRules\Requestors\UseCase;
+use Psr\Cache\CacheItemPoolInterface;
use Psr\Log\LoggerInterface;
/**
@@ -42,7 +42,7 @@ abstract class UseCaseProxyBuilder
protected $useCaseProxy;
/**
- * @var Cache
+ * @var CacheItemPoolInterface
*/
private $cache;
@@ -85,7 +85,7 @@ abstract public function create(UseCase $useCase);
/**
* @return UseCaseProxyBuilder
*/
- public function withCache(Cache $cache = null)
+ public function withCache(CacheItemPoolInterface $cache = null)
{
$this->cache = $cache;
diff --git a/src/OpenClassrooms/UseCase/BusinessRules/Entities/PaginatedCollection.php b/src/OpenClassrooms/UseCase/BusinessRules/Entities/PaginatedCollection.php
index b543911..21fcb73 100644
--- a/src/OpenClassrooms/UseCase/BusinessRules/Entities/PaginatedCollection.php
+++ b/src/OpenClassrooms/UseCase/BusinessRules/Entities/PaginatedCollection.php
@@ -99,7 +99,7 @@ public function getTotalPages()
/**
* @inheritDoc
*/
- public function getIterator()
+ public function getIterator(): \Traversable
{
return new \ArrayIterator($this->items);
}
diff --git a/src/OpenClassrooms/UseCase/BusinessRules/Responders/AbstractPaginatedUseCaseResponse.php b/src/OpenClassrooms/UseCase/BusinessRules/Responders/AbstractPaginatedUseCaseResponse.php
index df95692..aff1535 100644
--- a/src/OpenClassrooms/UseCase/BusinessRules/Responders/AbstractPaginatedUseCaseResponse.php
+++ b/src/OpenClassrooms/UseCase/BusinessRules/Responders/AbstractPaginatedUseCaseResponse.php
@@ -55,7 +55,7 @@ public function setItemsPerPage($itemsPerPage)
$this->itemsPerPage = $itemsPerPage;
}
- public function getIterator()
+ public function getIterator(): \Traversable
{
return new \ArrayIterator($this->items);
}
diff --git a/src/OpenClassrooms/UseCase/BusinessRules/Responders/Exceptions/InvalidPaginatedUseCaseResponseException.php b/src/OpenClassrooms/UseCase/BusinessRules/Responders/Exceptions/InvalidPaginatedUseCaseResponseException.php
index af76482..c5ab20f 100644
--- a/src/OpenClassrooms/UseCase/BusinessRules/Responders/Exceptions/InvalidPaginatedUseCaseResponseException.php
+++ b/src/OpenClassrooms/UseCase/BusinessRules/Responders/Exceptions/InvalidPaginatedUseCaseResponseException.php
@@ -2,8 +2,6 @@
namespace OpenClassrooms\UseCase\BusinessRules\Responders\Exceptions;
-use Exception;
-
/**
* @author Romain Kuzniak
* @deprecated
diff --git a/src/OpenClassrooms/UseCase/BusinessRules/Responders/PaginatedUseCaseResponse.php b/src/OpenClassrooms/UseCase/BusinessRules/Responders/PaginatedUseCaseResponse.php
index d506b53..90befab 100644
--- a/src/OpenClassrooms/UseCase/BusinessRules/Responders/PaginatedUseCaseResponse.php
+++ b/src/OpenClassrooms/UseCase/BusinessRules/Responders/PaginatedUseCaseResponse.php
@@ -19,7 +19,7 @@ public function getItems();
*/
public function getItemsPerPage();
- public function getIterator();
+ public function getIterator(): \Traversable;
/**
* @return int
diff --git a/tests/OpenClassrooms/UseCase/Application/Annotations/Event/EventTest.php b/tests/OpenClassrooms/UseCase/Application/Annotations/Event/EventTest.php
index 026dcae..a13bbbe 100644
--- a/tests/OpenClassrooms/UseCase/Application/Annotations/Event/EventTest.php
+++ b/tests/OpenClassrooms/UseCase/Application/Annotations/Event/EventTest.php
@@ -2,12 +2,14 @@
namespace OpenClassrooms\Tests\UseCase\Application\Annotations\Event;
+use Doctrine\Common\Annotations\AnnotationException;
use Doctrine\Common\Annotations\AnnotationReader;
+use PHPUnit\Framework\TestCase;
/**
* @author Romain Kuzniak
*/
-class EventTest extends \PHPUnit_Framework_TestCase
+class EventTest extends TestCase
{
/**
@@ -17,16 +19,18 @@ class EventTest extends \PHPUnit_Framework_TestCase
/**
* @test
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage Method "invalid method" is not allowed. Allowed: pre, post and onException
*/
public function InvalidMethod_ThrowException()
{
$class = new \ReflectionClass(new EventClassDummy());
+
+ $this->expectException(AnnotationException::class);
+ $this->expectExceptionMessage('Method "invalid method" is not allowed. Allowed: pre, post and onException');
+
$this->reader->getMethodAnnotation($class->getMethod('invalidMethod'), 'event');
}
- protected function setUp()
+ protected function setUp(): void
{
$this->reader = new AnnotationReader();
}
diff --git a/tests/OpenClassrooms/UseCase/Application/Annotations/Log/LogTest.php b/tests/OpenClassrooms/UseCase/Application/Annotations/Log/LogTest.php
index 6f4f658..174535d 100644
--- a/tests/OpenClassrooms/UseCase/Application/Annotations/Log/LogTest.php
+++ b/tests/OpenClassrooms/UseCase/Application/Annotations/Log/LogTest.php
@@ -2,12 +2,14 @@
namespace OpenClassrooms\Tests\UseCase\Application\Annotations\Log;
+use Doctrine\Common\Annotations\AnnotationException;
use Doctrine\Common\Annotations\AnnotationReader;
+use PHPUnit\Framework\TestCase;
/**
* @author Romain Kuzniak
*/
-class LogTest extends \PHPUnit_Framework_TestCase
+class LogTest extends TestCase
{
/**
@@ -17,27 +19,31 @@ class LogTest extends \PHPUnit_Framework_TestCase
/**
* @test
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage Level "invalid level" is not a valid PSR level. See Psr\Log\LogLevel.
*/
public function InvalidLevel_ThrowException()
{
$class = new \ReflectionClass(new LogClassDummy());
+
+ $this->expectException(AnnotationException::class);
+ $this->expectExceptionMessage('Level "invalid level" is not a valid PSR level. See Psr\Log\LogLevel.');
+
$this->reader->getMethodAnnotation($class->getMethod('invalidLevel'), 'log');
}
/**
* @test
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage Method "invalid method" is not allowed. Allowed: pre, post and onException
*/
public function InvalidMethod_ThrowException()
{
$class = new \ReflectionClass(new LogClassDummy());
+
+ $this->expectException(AnnotationException::class);
+ $this->expectExceptionMessage('Method "invalid method" is not allowed. Allowed: pre, post and onException');
+
$this->reader->getMethodAnnotation($class->getMethod('invalidMethod'), 'log');
}
- protected function setUp()
+ protected function setUp(): void
{
$this->reader = new AnnotationReader();
}
diff --git a/tests/OpenClassrooms/UseCase/Application/Annotations/Security/SecurityTest.php b/tests/OpenClassrooms/UseCase/Application/Annotations/Security/SecurityTest.php
index 502e984..8e27c77 100644
--- a/tests/OpenClassrooms/UseCase/Application/Annotations/Security/SecurityTest.php
+++ b/tests/OpenClassrooms/UseCase/Application/Annotations/Security/SecurityTest.php
@@ -2,12 +2,14 @@
namespace OpenClassrooms\Tests\UseCase\Application\Annotations\Security;
+use Doctrine\Common\Annotations\AnnotationException;
use Doctrine\Common\Annotations\AnnotationReader;
+use PHPUnit\Framework\TestCase;
/**
* @author Romain Kuzniak
*/
-class SecurityTest extends \PHPUnit_Framework_TestCase
+class SecurityTest extends TestCase
{
/**
@@ -17,16 +19,18 @@ class SecurityTest extends \PHPUnit_Framework_TestCase
/**
* @test
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage Roles MUST be defined
*/
public function WithoutRole_ThrowException()
{
$class = new \ReflectionClass(new SecurityClassDummy());
+
+ $this->expectException(AnnotationException::class);
+ $this->expectExceptionMessage('Roles MUST be defined');
+
$this->reader->getMethodAnnotation($class->getMethod('method'), 'security');
}
- protected function setUp()
+ protected function setUp(): void
{
$this->reader = new AnnotationReader();
}
diff --git a/tests/OpenClassrooms/UseCase/Application/Services/Cache/CacheSpy.php b/tests/OpenClassrooms/UseCase/Application/Services/Cache/CacheSpy.php
index a828de4..ef269d0 100644
--- a/tests/OpenClassrooms/UseCase/Application/Services/Cache/CacheSpy.php
+++ b/tests/OpenClassrooms/UseCase/Application/Services/Cache/CacheSpy.php
@@ -2,77 +2,38 @@
namespace OpenClassrooms\Tests\UseCase\Application\Services\Cache;
-use Doctrine\Common\Cache\ArrayCache;
-use OpenClassrooms\Cache\Cache\CacheImpl;
+use Psr\Cache\CacheItemInterface;
+use Symfony\Component\Cache\Adapter\ArrayAdapter;
+use Symfony\Component\Cache\CacheItem;
/**
* @author Romain Kuzniak
*/
-class CacheSpy extends CacheImpl
+class CacheSpy extends ArrayAdapter
{
-
- /**
- * @var int
- */
- public $lifeTime;
-
- /**
- * @var string
- */
- public $namespaceId;
-
- /**
- * @var bool
- */
- public $saved = false;
-
/**
- * @var bool
+ * @var array
*/
- public $savedWithNamespace = false;
+ public array $saved = [];
/**
- * @var bool
+ * @var array
*/
- public $fetched = false;
+ public array $getted = [];
- /**
- * @var bool
- */
- public $fetchedWithNamespace = false;
-
- public function __construct()
- {
- parent::__construct(new ArrayCache());
- }
-
- public function save($id, $data, $lifeTime = null)
+ public function save(CacheItemInterface $item): bool
{
- $this->saved = true;
- $this->lifeTime = $lifeTime;
+ $this->saved[$item->getKey()] = (new \ReflectionProperty($item, 'expiry'))->getValue($item);
- return parent::save($id, $data, $lifeTime);
+ return parent::save($item);
}
- public function saveWithNamespace($id, $data, $namespaceId = null, $lifeTime = null)
+ public function getItem(mixed $key): CacheItem
{
- $this->savedWithNamespace = true;
- $this->namespaceId = $namespaceId;
-
- return parent::saveWithNamespace($id, $data, $namespaceId, $lifeTime);
- }
+ $item = parent::getItem($key);
- public function fetch($id)
- {
- $this->fetched = true;
-
- return parent::fetch($id);
- }
-
- public function fetchWithNamespace($id, $namespaceId = null)
- {
- $this->fetchedWithNamespace = true;
+ $this->getted[$item->getKey()] = $item->isHit();
- return parent::fetchWithNamespace($id, $namespaceId);
+ return $item;
}
}
diff --git a/tests/OpenClassrooms/UseCase/Application/Services/Event/EventFactoryTest.php b/tests/OpenClassrooms/UseCase/Application/Services/Event/EventFactoryTest.php
index 374bc16..4b7879e 100644
--- a/tests/OpenClassrooms/UseCase/Application/Services/Event/EventFactoryTest.php
+++ b/tests/OpenClassrooms/UseCase/Application/Services/Event/EventFactoryTest.php
@@ -2,18 +2,22 @@
namespace OpenClassrooms\Tests\UseCase\Application\Services\Event;
+use OpenClassrooms\UseCase\Application\Services\Event\Exceptions\InvalidEventNameException;
+use PHPUnit\Framework\TestCase;
+
/**
* @author Romain Kuzniak
*/
-class EventFactoryTest extends \PHPUnit_Framework_TestCase
+class EventFactoryTest extends TestCase
{
/**
* @test
- * @expectedException \OpenClassrooms\UseCase\Application\Services\Event\Exceptions\InvalidEventNameException
*/
public function InvalidEventName_Make_ThrowException()
{
$factory = new EventFactorySpy();
+
+ $this->expectException(InvalidEventNameException::class);
$factory->make(EventFactorySpy::INVALID_EVENT_NAME);
}
}
diff --git a/tests/OpenClassrooms/UseCase/Application/Services/Log/LoggerSpy.php b/tests/OpenClassrooms/UseCase/Application/Services/Log/LoggerSpy.php
index 7b0eda5..7519b3c 100644
--- a/tests/OpenClassrooms/UseCase/Application/Services/Log/LoggerSpy.php
+++ b/tests/OpenClassrooms/UseCase/Application/Services/Log/LoggerSpy.php
@@ -18,7 +18,7 @@ class LoggerSpy implements LoggerInterface
public static $level;
/**
- * @var string
+ * @var string[]
*/
public static $message;
@@ -41,7 +41,7 @@ public function __construct()
*
* @return null
*/
- public function log($level, $message, array $context = array())
+ public function log($level, $message, array $context = array()): void
{
self::$level[] = $level;
self::$message[] = $message;
diff --git a/tests/OpenClassrooms/UseCase/Application/Services/Proxy/Strategies/Requestors/Cache/DTO/CacheProxyStrategyRequestBuilderImplTest.php b/tests/OpenClassrooms/UseCase/Application/Services/Proxy/Strategies/Requestors/Cache/DTO/CacheProxyStrategyRequestBuilderImplTest.php
index c457197..4d78059 100644
--- a/tests/OpenClassrooms/UseCase/Application/Services/Proxy/Strategies/Requestors/Cache/DTO/CacheProxyStrategyRequestBuilderImplTest.php
+++ b/tests/OpenClassrooms/UseCase/Application/Services/Proxy/Strategies/Requestors/Cache/DTO/CacheProxyStrategyRequestBuilderImplTest.php
@@ -3,19 +3,23 @@
namespace OpenClassrooms\Tests\UseCase\Application\Services\Proxy\Strategies\Requestors\Cache\DTO;
use OpenClassrooms\UseCase\Application\Services\Proxy\Strategies\Impl\Cache\DTO\CacheProxyStrategyRequestBuilderImpl;
+use OpenClassrooms\UseCase\Application\Services\Proxy\Strategies\Requestors\Cache\Exceptions\CacheIdMustBeDefinedException;
+use PHPUnit\Framework\TestCase;
/**
* @author Romain Kuzniak
*/
-class CacheProxyStrategyRequestBuilderImplTest extends \PHPUnit_Framework_TestCase
+class CacheProxyStrategyRequestBuilderImplTest extends TestCase
{
/**
* @test
- * @expectedException \OpenClassrooms\UseCase\Application\Services\Proxy\Strategies\Requestors\Cache\Exceptions\CacheIdMustBeDefinedException
*/
public function Build_ThrowsException()
{
$builder = new CacheProxyStrategyRequestBuilderImpl();
+
+ $this->expectException(CacheIdMustBeDefinedException::class);
+
$builder
->create()
->build();
diff --git a/tests/OpenClassrooms/UseCase/Application/Services/Proxy/Strategies/Requestors/Event/DTO/EventProxyStrategyRequestBuilderImplTest.php b/tests/OpenClassrooms/UseCase/Application/Services/Proxy/Strategies/Requestors/Event/DTO/EventProxyStrategyRequestBuilderImplTest.php
index 9819caa..138ca39 100644
--- a/tests/OpenClassrooms/UseCase/Application/Services/Proxy/Strategies/Requestors/Event/DTO/EventProxyStrategyRequestBuilderImplTest.php
+++ b/tests/OpenClassrooms/UseCase/Application/Services/Proxy/Strategies/Requestors/Event/DTO/EventProxyStrategyRequestBuilderImplTest.php
@@ -3,19 +3,22 @@
namespace OpenClassrooms\Tests\UseCase\Application\Services\Proxy\Strategies\Requestors\Event\DTO;
use OpenClassrooms\UseCase\Application\Services\Proxy\Strategies\Impl\Event\DTO\EventProxyStrategyRequestBuilderImpl;
+use OpenClassrooms\UseCase\Application\Services\Proxy\Strategies\Requestors\Event\Exceptions\EventNameMustBeDefinedException;
+use PHPUnit\Framework\TestCase;
/**
* @author Romain Kuzniak
*/
-class EventProxyStrategyRequestBuilderImplTest extends \PHPUnit_Framework_TestCase
+class EventProxyStrategyRequestBuilderImplTest extends TestCase
{
/**
* @test
- * @expectedException \OpenClassrooms\UseCase\Application\Services\Proxy\Strategies\Requestors\Event\Exceptions\EventNameMustBeDefinedException
*/
public function WithoutEventName_Build_ThrowException()
{
$builder = new EventProxyStrategyRequestBuilderImpl();
+ $this->expectException(EventNameMustBeDefinedException::class);
+
$builder->create()->build();
}
}
diff --git a/tests/OpenClassrooms/UseCase/Application/Services/Proxy/Strategies/Requestors/ProxyStrategyBagFactoryTest.php b/tests/OpenClassrooms/UseCase/Application/Services/Proxy/Strategies/Requestors/ProxyStrategyBagFactoryTest.php
index 55ac61b..d603734 100644
--- a/tests/OpenClassrooms/UseCase/Application/Services/Proxy/Strategies/Requestors/ProxyStrategyBagFactoryTest.php
+++ b/tests/OpenClassrooms/UseCase/Application/Services/Proxy/Strategies/Requestors/ProxyStrategyBagFactoryTest.php
@@ -2,20 +2,23 @@
namespace OpenClassrooms\Tests\UseCase\Application\Services\Proxy\Strategies\Requestors;
+use OpenClassrooms\UseCase\Application\Services\Proxy\Strategies\Exceptions\UnSupportedAnnotationException;
use OpenClassrooms\UseCase\Application\Services\Proxy\Strategies\Impl\ProxyStrategyBagFactoryImpl;
+use PHPUnit\Framework\TestCase;
/**
* @author Romain Kuzniak
*/
-class ProxyStrategyBagFactoryTest extends \PHPUnit_Framework_TestCase
+class ProxyStrategyBagFactoryTest extends TestCase
{
/**
* @test
- * @expectedException \OpenClassrooms\UseCase\Application\Services\Proxy\Strategies\Exceptions\UnSupportedAnnotationException
*/
public function UnsupportedAnnotation_Make_ThrowException()
{
$factory = new ProxyStrategyBagFactoryImpl();
+ $this->expectException(UnSupportedAnnotationException::class);
+
$factory->make('unsupported annotation');
}
}
diff --git a/tests/OpenClassrooms/UseCase/Application/Services/Proxy/Strategies/Requestors/ProxyStrategyRequestFactoryTest.php b/tests/OpenClassrooms/UseCase/Application/Services/Proxy/Strategies/Requestors/ProxyStrategyRequestFactoryTest.php
index da14d18..1fe6b4d 100644
--- a/tests/OpenClassrooms/UseCase/Application/Services/Proxy/Strategies/Requestors/ProxyStrategyRequestFactoryTest.php
+++ b/tests/OpenClassrooms/UseCase/Application/Services/Proxy/Strategies/Requestors/ProxyStrategyRequestFactoryTest.php
@@ -6,30 +6,36 @@
use OpenClassrooms\Tests\UseCase\BusinessRules\Requestors\UseCaseRequestStub;
use OpenClassrooms\Tests\UseCase\BusinessRules\Responders\Doubles\UseCaseResponseStub;
use OpenClassrooms\Tests\UseCase\BusinessRules\UseCases\UseCaseStub;
+use OpenClassrooms\UseCase\Application\Services\Proxy\Strategies\Exceptions\UnSupportedAnnotationException;
use OpenClassrooms\UseCase\Application\Services\Proxy\Strategies\Impl\ProxyStrategyRequestFactoryImpl;
+use PHPUnit\Framework\TestCase;
/**
* @author Romain Kuzniak
*/
-class ProxyStrategyRequestFactoryTest extends \PHPUnit_Framework_TestCase
+class ProxyStrategyRequestFactoryTest extends TestCase
{
/**
* @test
- * @expectedException \OpenClassrooms\UseCase\Application\Services\Proxy\Strategies\Exceptions\UnSupportedAnnotationException
*/
public function UnsupportedAnnotation_CreatePreExecuteRequest_ThrowException()
{
$factory = new ProxyStrategyRequestFactoryImpl();
+
+ $this->expectException(UnSupportedAnnotationException::class);
+
$factory->createPreExecuteRequest('unsupported annotation', new UseCaseStub(), new UseCaseRequestStub());
}
/**
* @test
- * @expectedException \OpenClassrooms\UseCase\Application\Services\Proxy\Strategies\Exceptions\UnSupportedAnnotationException
*/
public function UnsupportedAnnotation_CreatePostExecuteRequest_ThrowException()
{
$factory = new ProxyStrategyRequestFactoryImpl();
+
+ $this->expectException(UnSupportedAnnotationException::class);
+
$factory->createPostExecuteRequest(
'unsupported annotation',
new UseCaseStub(),
@@ -40,11 +46,13 @@ public function UnsupportedAnnotation_CreatePostExecuteRequest_ThrowException()
/**
* @test
- * @expectedException \OpenClassrooms\UseCase\Application\Services\Proxy\Strategies\Exceptions\UnSupportedAnnotationException
*/
public function UnsupportedAnnotation_CreateOnExceptionRequest_ThrowException()
{
$factory = new ProxyStrategyRequestFactoryImpl();
+
+ $this->expectException(UnSupportedAnnotationException::class);
+
$factory->createOnExceptionRequest(
'unsupported annotation',
new UseCaseStub(),
diff --git a/tests/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/AbstractUseCaseProxyTest.php b/tests/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/AbstractUseCaseProxyTestCase.php
similarity index 96%
rename from tests/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/AbstractUseCaseProxyTest.php
rename to tests/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/AbstractUseCaseProxyTestCase.php
index 1368a63..d6b37d8 100644
--- a/tests/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/AbstractUseCaseProxyTest.php
+++ b/tests/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/AbstractUseCaseProxyTestCase.php
@@ -22,11 +22,12 @@
use OpenClassrooms\UseCase\Application\Services\Proxy\Strategies\Impl\Transaction\TransactionProxyStrategy;
use OpenClassrooms\UseCase\Application\Services\Proxy\UseCases\Impl\UseCaseProxyImpl;
use OpenClassrooms\UseCase\Application\Services\Proxy\UseCases\UseCaseProxy;
+use PHPUnit\Framework\TestCase;
/**
* @author Romain Kuzniak
*/
-abstract class AbstractUseCaseProxyTest extends \PHPUnit_Framework_TestCase
+abstract class AbstractUseCaseProxyTestCase extends TestCase
{
/**
@@ -39,6 +40,11 @@ abstract class AbstractUseCaseProxyTest extends \PHPUnit_Framework_TestCase
*/
protected $cache;
+ /**
+ * @var string[]
+ */
+ protected array $logs = [];
+
/**
* @var EventSenderSpy
*/
@@ -74,7 +80,7 @@ abstract class AbstractUseCaseProxyTest extends \PHPUnit_Framework_TestCase
*/
private $proxyStrategyRequestFactory;
- protected function setUp()
+ protected function setUp(): void
{
$this->initUseCaseProxy();
@@ -166,7 +172,7 @@ protected function buildLogStrategy()
$this->proxyStrategyRequestFactory->setLogProxyStrategyRequestBuilder(new LogProxyStrategyRequestBuilderImpl());
}
- protected function tearDown()
+ protected function tearDown(): void
{
LoggerSpy::$context = array();
LoggerSpy::$level = array();
diff --git a/tests/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/CacheUseCaseProxyTest.php b/tests/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/CacheUseCaseProxyTest.php
index ef7bcf2..b312f1d 100644
--- a/tests/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/CacheUseCaseProxyTest.php
+++ b/tests/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/CacheUseCaseProxyTest.php
@@ -13,7 +13,7 @@
/**
* @author Romain Kuzniak
*/
-class CacheUseCaseProxyTest extends AbstractUseCaseProxyTest
+class CacheUseCaseProxyTest extends AbstractUseCaseProxyTestCase
{
/**
* @test
@@ -23,7 +23,7 @@ public function OnlyCache_ReturnResponse()
$this->useCaseProxy->setUseCase(new OnlyCacheUseCaseStub());
$response = $this->useCaseProxy->execute(new UseCaseRequestStub());
$this->assertEquals(new UseCaseResponseStub(), $response);
- $this->assertTrue($this->cache->saved);
+ $this->assertNotEmpty($this->cache->saved);
}
/**
@@ -33,12 +33,15 @@ public function Cached_OnlyCache_ReturnResponse()
{
$this->useCaseProxy->setUseCase(new OnlyCacheUseCaseStub());
$this->useCaseProxy->execute(new UseCaseRequestStub());
- $this->assertTrue($this->cache->saved);
- $this->cache->saved = false;
+ $this->assertCount(1, $this->cache->saved);
+
+ $this->cache->saved = [];
+
$response = $this->useCaseProxy->execute(new UseCaseRequestStub());
$this->assertEquals(new UseCaseResponseStub(), $response);
- $this->assertTrue($this->cache->fetched);
- $this->assertFalse($this->cache->saved);
+ $this->assertCount(1, $this->cache->getted);
+ $this->assertContains(true, $this->cache->getted);
+ $this->assertEmpty($this->cache->saved);
}
/**
@@ -49,10 +52,10 @@ public function WithNamespace_Cache_ReturnResponse()
$this->useCaseProxy->setUseCase(new NamespaceCacheUseCaseStub());
$response = $this->useCaseProxy->execute(new UseCaseRequestStub());
$this->assertEquals(new UseCaseResponseStub(), $response);
- $this->assertTrue($this->cache->savedWithNamespace);
- $this->assertEquals(
+ $this->assertCount(2, $this->cache->saved);
+ $this->assertContains(
NamespaceCacheUseCaseStub::NAMESPACE_PREFIX.UseCaseRequestStub::FIELD_VALUE,
- $this->cache->namespaceId
+ array_keys($this->cache->saved)
);
}
@@ -63,12 +66,15 @@ public function CachedWithNamespace_Cache_ReturnResponse()
{
$this->useCaseProxy->setUseCase(new NamespaceCacheUseCaseStub());
$this->useCaseProxy->execute(new UseCaseRequestStub());
- $this->assertTrue($this->cache->savedWithNamespace);
- $this->cache->savedWithNamespace = false;
+ $this->assertCount(2, $this->cache->saved);
+
+ $this->cache->saved = [];
+ $this->cache->getted = [];
+
$response = $this->useCaseProxy->execute(new UseCaseRequestStub());
$this->assertEquals(new UseCaseResponseStub(), $response);
- $this->assertTrue($this->cache->fetched);
- $this->assertFalse($this->cache->savedWithNamespace);
+ $this->assertCount(2, $this->cache->getted);
+ $this->assertEmpty($this->cache->saved);
}
/**
@@ -79,8 +85,10 @@ public function WithLifeTime_Cache_ReturnResponse()
$this->useCaseProxy->setUseCase(new LifeTimeCacheUseCaseStub());
$response = $this->useCaseProxy->execute(new UseCaseRequestStub());
$this->assertEquals(new UseCaseResponseStub(), $response);
- $this->assertTrue($this->cache->saved);
- $this->assertEquals(LifeTimeCacheUseCaseStub::LIFETIME, $this->cache->lifeTime);
+ $this->assertCount(1, $this->cache->saved);
+
+ $this->assertNotContains(null, $this->cache->saved);
+ $this->assertEqualsWithDelta(time() + LifeTimeCacheUseCaseStub::LIFETIME, array_pop($this->cache->saved), 2.0);
}
/**
@@ -93,7 +101,7 @@ public function CacheOnException_DonTSave()
$this->useCaseProxy->execute(new UseCaseRequestStub());
$this->fail('Exception should be thrown');
} catch (UseCaseException $e) {
- $this->assertFalse($this->cache->saved);
+ $this->assertEmpty($this->cache->saved);
}
}
}
diff --git a/tests/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/ConfigurationUseCaseProxyTest.php b/tests/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/ConfigurationUseCaseProxyTest.php
index 4e984ea..afc58cb 100644
--- a/tests/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/ConfigurationUseCaseProxyTest.php
+++ b/tests/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/ConfigurationUseCaseProxyTest.php
@@ -15,7 +15,7 @@
/**
* @author Romain Kuzniak
*/
-class ConfigurationUseCaseProxyTest extends AbstractUseCaseProxyTest
+class ConfigurationUseCaseProxyTest extends AbstractUseCaseProxyTestCase
{
/**
* @test
@@ -75,7 +75,7 @@ public function WithEventAnnotationWithCacheConfiguration_ReturnResponse()
$this->executeAndAssert();
}
- protected function setUp()
+ protected function setUp(): void
{
$this->initUseCaseProxy();
}
diff --git a/tests/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/EventUseCaseProxyTest.php b/tests/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/EventUseCaseProxyTest.php
index a240b77..4938161 100644
--- a/tests/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/EventUseCaseProxyTest.php
+++ b/tests/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/EventUseCaseProxyTest.php
@@ -15,7 +15,7 @@
/**
* @author Romain Kuzniak
*/
-class EventUseCaseProxyTest extends AbstractUseCaseProxyTest
+class EventUseCaseProxyTest extends AbstractUseCaseProxyTestCase
{
const EVENT_PRE_NAME_PREFIX = 'use_case.pre.';
diff --git a/tests/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/LogUseCaseProxyTest.php b/tests/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/LogUseCaseProxyTest.php
index 537fa13..7e97a40 100644
--- a/tests/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/LogUseCaseProxyTest.php
+++ b/tests/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/LogUseCaseProxyTest.php
@@ -17,7 +17,7 @@
/**
* @author Romain Kuzniak
*/
-class LogUseCaseProxyTest extends AbstractUseCaseProxyTest
+class LogUseCaseProxyTest extends AbstractUseCaseProxyTestCase
{
/**
* @test
diff --git a/tests/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/SecurityUseCaseProxyTest.php b/tests/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/SecurityUseCaseProxyTest.php
index 54dd80f..a1674da 100644
--- a/tests/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/SecurityUseCaseProxyTest.php
+++ b/tests/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/SecurityUseCaseProxyTest.php
@@ -2,6 +2,7 @@
namespace OpenClassrooms\Tests\UseCase\Application\Services\Proxy\UseCases;
+use OpenClassrooms\Tests\UseCase\Application\Services\Security\Exceptions\AccessDeniedException;
use OpenClassrooms\Tests\UseCase\BusinessRules\Requestors\UseCaseRequestStub;
use OpenClassrooms\Tests\UseCase\BusinessRules\UseCases\Security\FieldRoleSecurityUseCaseStub;
use OpenClassrooms\Tests\UseCase\BusinessRules\UseCases\Security\ManyRolesSecurityUseCaseStub;
@@ -12,14 +13,15 @@
/**
* @author Romain Kuzniak
*/
-class SecurityUseCaseProxyTest extends AbstractUseCaseProxyTest
+class SecurityUseCaseProxyTest extends AbstractUseCaseProxyTestCase
{
/**
* @test
- * @expectedException \OpenClassrooms\Tests\UseCase\Application\Services\Security\Exceptions\AccessDeniedException
*/
public function OnlyRoleNotAuthorized_ThrowException()
{
+ $this->expectException(AccessDeniedException::class);
+
$this->useCaseProxy->setUseCase(new OnlyRoleNotAuthorizedSecurityUseCaseStub());
$this->useCaseProxy->execute(new UseCaseRequestStub());
}
diff --git a/tests/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/TransactionUseCaseProxyTest.php b/tests/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/TransactionUseCaseProxyTest.php
index a1a2e7a..dc58535 100644
--- a/tests/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/TransactionUseCaseProxyTest.php
+++ b/tests/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/TransactionUseCaseProxyTest.php
@@ -11,7 +11,7 @@
/**
* @author Romain Kuzniak
*/
-class TransactionUseCaseProxyTest extends AbstractUseCaseProxyTest
+class TransactionUseCaseProxyTest extends AbstractUseCaseProxyTestCase
{
/**
* @test
diff --git a/tests/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/UseCaseProxyBuilderTest.php b/tests/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/UseCaseProxyBuilderTest.php
index 3e0ca20..9df1668 100644
--- a/tests/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/UseCaseProxyBuilderTest.php
+++ b/tests/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/UseCaseProxyBuilderTest.php
@@ -3,7 +3,6 @@
namespace OpenClassrooms\Tests\UseCase\Application\Services\Proxy\UseCases;
use Doctrine\Common\Annotations\AnnotationReader;
-use OpenClassrooms\Tests\UseCase\Application\Services\Cache\CacheSpy;
use OpenClassrooms\Tests\UseCase\Application\Services\Event\EventFactorySpy;
use OpenClassrooms\Tests\UseCase\Application\Services\Event\EventSenderSpy;
use OpenClassrooms\Tests\UseCase\Application\Services\Log\LoggerSpy;
@@ -17,13 +16,22 @@
use OpenClassrooms\Tests\UseCase\BusinessRules\UseCases\Security\OnlyRoleSecurityUseCaseStub;
use OpenClassrooms\Tests\UseCase\BusinessRules\UseCases\Transaction\OnlyTransactionUseCaseStub;
use OpenClassrooms\Tests\UseCase\BusinessRules\UseCases\Workflow\AllAnnotationsUseCaseStub;
+use OpenClassrooms\UseCase\Application\Services\Proxy\UseCases\Exceptions\CacheIsNotDefinedException;
+use OpenClassrooms\UseCase\Application\Services\Proxy\UseCases\Exceptions\EventFactoryIsNotDefinedException;
+use OpenClassrooms\UseCase\Application\Services\Proxy\UseCases\Exceptions\EventIsNotDefinedException;
+use OpenClassrooms\UseCase\Application\Services\Proxy\UseCases\Exceptions\LoggerIsNotDefinedException;
+use OpenClassrooms\UseCase\Application\Services\Proxy\UseCases\Exceptions\ReaderIsNotDefinedException;
+use OpenClassrooms\UseCase\Application\Services\Proxy\UseCases\Exceptions\SecurityIsNotDefinedException;
+use OpenClassrooms\UseCase\Application\Services\Proxy\UseCases\Exceptions\TransactionIsNotDefinedException;
use OpenClassrooms\UseCase\Application\Services\Proxy\UseCases\Impl\UseCaseProxyBuilderImpl;
use OpenClassrooms\UseCase\Application\Services\Proxy\UseCases\UseCaseProxyBuilder;
+use PHPUnit\Framework\TestCase;
+use Symfony\Component\Cache\Adapter\ArrayAdapter;
/**
* @author Romain Kuzniak
*/
-class UseCaseProxyBuilderTest extends \PHPUnit_Framework_TestCase
+class UseCaseProxyBuilderTest extends TestCase
{
const USE_CASE_PROXY_CLASS = 'OpenClassrooms\UseCase\Application\Services\Proxy\UseCases\UseCaseProxy';
@@ -34,19 +42,21 @@ class UseCaseProxyBuilderTest extends \PHPUnit_Framework_TestCase
/**
* @test
- * @expectedException \OpenClassrooms\UseCase\Application\Services\Proxy\UseCases\Exceptions\ReaderIsNotDefinedException
*/
public function WithoutReader_Build_ThrowException()
{
+ $this->expectException(ReaderIsNotDefinedException::class);
+
$this->builder->create(new AllAnnotationsUseCaseStub())->build();
}
/**
* @test
- * @expectedException \OpenClassrooms\UseCase\Application\Services\Proxy\UseCases\Exceptions\CacheIsNotDefinedException
*/
public function WithoutCacheUseCaseWithCacheAnnotation_Build_ThrowException()
{
+ $this->expectException(CacheIsNotDefinedException::class);
+
$this->builder
->create(new OnlyCacheUseCaseStub())
->withReader(new AnnotationReader())
@@ -61,7 +71,7 @@ public function WithCacheUseCaseWithCacheAnnotation_Build_ReturnUseCaseProxy()
$proxy = $this->builder
->create(new OnlyCacheUseCaseStub())
->withReader(new AnnotationReader())
- ->withCache(new CacheSpy())
+ ->withCache(new ArrayAdapter())
->build();
$this->assertInstanceOf(self::USE_CASE_PROXY_CLASS, $proxy);
@@ -71,10 +81,11 @@ public function WithCacheUseCaseWithCacheAnnotation_Build_ReturnUseCaseProxy()
/**
* @test
- * @expectedException \OpenClassrooms\UseCase\Application\Services\Proxy\UseCases\Exceptions\EventIsNotDefinedException
*/
public function WithoutEventUseCaseWithEventAnnotation_Build_ThrowException()
{
+ $this->expectException(EventIsNotDefinedException::class);
+
$this->builder
->create(new OnlyEventNameEventUseCaseStub())
->withReader(new AnnotationReader())
@@ -83,10 +94,11 @@ public function WithoutEventUseCaseWithEventAnnotation_Build_ThrowException()
/**
* @test
- * @expectedException \OpenClassrooms\UseCase\Application\Services\Proxy\UseCases\Exceptions\EventFactoryIsNotDefinedException
*/
public function WithoutEventFactoryUseCaseWithEventAnnotation_Build_ThrowException()
{
+ $this->expectException(EventFactoryIsNotDefinedException::class);
+
$this->builder
->create(new OnlyEventNameEventUseCaseStub())
->withReader(new AnnotationReader())
@@ -113,10 +125,11 @@ public function WithEventUseCaseWithEventAnnotation_Build_ReturnUseCaseProxy()
/**
* @test
- * @expectedException \OpenClassrooms\UseCase\Application\Services\Proxy\UseCases\Exceptions\LoggerIsNotDefinedException
*/
public function WithoutLoggerUseCaseWithLogAnnotation_Build_ThrowException()
{
+ $this->expectException(LoggerIsNotDefinedException::class);
+
$this->builder
->create(new OnlyLogUseCaseStub())
->withReader(new AnnotationReader())
@@ -141,10 +154,11 @@ public function WithLogUseCaseWithLogAnnotation_Build_ReturnUseCaseProxy()
/**
* @test
- * @expectedException \OpenClassrooms\UseCase\Application\Services\Proxy\UseCases\Exceptions\SecurityIsNotDefinedException
*/
public function WithoutSecurityUseCaseWithSecurityAnnotation_Build_ThrowException()
{
+ $this->expectException(SecurityIsNotDefinedException::class);
+
$this->builder
->create(new OnlyRoleSecurityUseCaseStub())
->withReader(new AnnotationReader())
@@ -169,10 +183,11 @@ public function WithSecurityUseCaseWithSecurityAnnotation_Build_ReturnUseCasePro
/**
* @test
- * @expectedException \OpenClassrooms\UseCase\Application\Services\Proxy\UseCases\Exceptions\TransactionIsNotDefinedException
*/
public function WithoutTransactionUseCaseWithTransactionAnnotation_Build_ThrowException()
{
+ $this->expectException(TransactionIsNotDefinedException::class);
+
$this->builder
->create(new OnlyTransactionUseCaseStub())
->withReader(new AnnotationReader())
@@ -203,7 +218,7 @@ public function Build_ReturnUseCaseProxy()
$proxy = $this->builder
->create(new AllAnnotationsUseCaseStub())
->withReader(new AnnotationReader())
- ->withCache(new CacheSpy())
+ ->withCache(new ArrayAdapter())
->withEventSender(new EventSenderSpy())
->withEventFactory(new EventFactorySpy())
->withLogger(new LoggerSpy())
@@ -216,7 +231,7 @@ public function Build_ReturnUseCaseProxy()
$this->assertEquals(new UseCaseResponseStub(), $proxy->execute(new UseCaseRequestStub()));
}
- protected function setUp()
+ protected function setUp(): void
{
$this->builder = new UseCaseProxyBuilderImpl();
}
diff --git a/tests/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/WorkflowUseCaseProxyTest.php b/tests/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/WorkflowUseCaseProxyTest.php
index 748c863..080fc3b 100644
--- a/tests/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/WorkflowUseCaseProxyTest.php
+++ b/tests/OpenClassrooms/UseCase/Application/Services/Proxy/UseCases/WorkflowUseCaseProxyTest.php
@@ -16,7 +16,7 @@
/**
* @author Romain Kuzniak
*/
-class WorkflowUseCaseProxyTest extends AbstractUseCaseProxyTest
+class WorkflowUseCaseProxyTest extends AbstractUseCaseProxyTestCase
{
/**
* @test
@@ -58,8 +58,8 @@ public function SecurityException_ThrowException()
private function assertCacheWasNotCalled()
{
- $this->assertFalse($this->cache->fetched);
- $this->assertFalse($this->cache->saved);
+ $this->assertEmpty($this->cache->getted);
+ $this->assertEmpty($this->cache->saved);
}
private function assertTransactionWasCalledOnUnAuthorizedException()
@@ -97,8 +97,8 @@ public function AllAnnotation_ReturnResponse()
private function assertCacheSaveWasCalled()
{
- $this->assertTrue($this->cache->fetched);
- $this->assertTrue($this->cache->saved);
+ $this->assertNotEmpty($this->cache->getted);
+ $this->assertNotEmpty($this->cache->saved);
}
private function assertTransactionWasCalled()
@@ -141,8 +141,8 @@ public function Cached_ReturnResponse()
private function resetCache()
{
- $this->cache->fetched = false;
- $this->cache->saved = false;
+ $this->cache->getted = [];
+ $this->cache->saved = [];
}
private function resetEvent()
@@ -166,8 +166,8 @@ private function resetTransaction()
private function assertCacheWasCalled()
{
- $this->assertTrue($this->cache->fetched);
- $this->assertFalse($this->cache->saved);
+ $this->assertContains(true, $this->cache->getted);
+ $this->assertEmpty($this->cache->saved);
}
private function assertTransactionWasNotCalled()
@@ -196,8 +196,9 @@ public function AllAnnotationException_ThrowException()
private function assertCacheSaveWasNotCalled()
{
- $this->assertTrue($this->cache->fetched);
- $this->assertFalse($this->cache->saved);
+ $this->assertNotEmpty($this->cache->getted);
+ $this->assertContains(false, $this->cache->getted);
+ $this->assertEmpty($this->cache->saved);
}
private function assertTransactionWasCalledOnException()
diff --git a/tests/OpenClassrooms/UseCase/Application/Services/Security/DTO/SecurityProxyStrategyRequestBuilderImplTest.php b/tests/OpenClassrooms/UseCase/Application/Services/Security/DTO/SecurityProxyStrategyRequestBuilderImplTest.php
index 3f75b83..b3fde23 100644
--- a/tests/OpenClassrooms/UseCase/Application/Services/Security/DTO/SecurityProxyStrategyRequestBuilderImplTest.php
+++ b/tests/OpenClassrooms/UseCase/Application/Services/Security/DTO/SecurityProxyStrategyRequestBuilderImplTest.php
@@ -3,18 +3,21 @@
namespace OpenClassrooms\Tests\UseCase\Application\Services\Security\DTO;
use OpenClassrooms\UseCase\Application\Services\Proxy\Strategies\Impl\Security\DTO\SecurityProxyStrategyRequestBuilderImpl;
+use OpenClassrooms\UseCase\Application\Services\Proxy\Strategies\Requestors\Security\Exceptions\AttributesMustBeDefinedException;
+use PHPUnit\Framework\TestCase;
/**
* @author Romain Kuzniak
*/
-class SecurityProxyStrategyRequestBuilderImplTest extends \PHPUnit_Framework_TestCase
+class SecurityProxyStrategyRequestBuilderImplTest extends TestCase
{
/**
* @test
- * @expectedException \OpenClassrooms\UseCase\Application\Services\Proxy\Strategies\Requestors\Security\Exceptions\AttributesMustBeDefinedException
*/
public function WithoutAttributes_Build_ThrowException()
{
+ $this->expectException(AttributesMustBeDefinedException::class);
+
$builder = new SecurityProxyStrategyRequestBuilderImpl();
$builder
->create()
diff --git a/tests/OpenClassrooms/UseCase/Application/Services/Transaction/Impl/PDOTransactionAdapterTest.php b/tests/OpenClassrooms/UseCase/Application/Services/Transaction/Impl/PDOTransactionAdapterTest.php
index da44114..1bca19f 100644
--- a/tests/OpenClassrooms/UseCase/Application/Services/Transaction/Impl/PDOTransactionAdapterTest.php
+++ b/tests/OpenClassrooms/UseCase/Application/Services/Transaction/Impl/PDOTransactionAdapterTest.php
@@ -4,11 +4,12 @@
use OpenClassrooms\UseCase\Application\Services\Transaction\Impl\PDOTransactionAdapter;
use OpenClassrooms\UseCase\Application\Services\Transaction\Transaction;
+use PHPUnit\Framework\TestCase;
/**
* @author Romain Kuzniak
*/
-class PDOTransactionAdapterTest extends \PHPUnit_Framework_TestCase
+class PDOTransactionAdapterTest extends TestCase
{
/**
@@ -34,11 +35,11 @@ public function BeginTransaction_ReturnTransaction()
/**
* @test
- * @expectedException \PDOException
- * @expectedExceptionMessage There is no active transaction
*/
public function WithoutTransaction_Commit_ThrowException()
{
+ $this->expectException(\PDOException::class);
+ $this->expectExceptionMessage('There is no active transaction');
$this->transaction->commit();
}
@@ -56,11 +57,12 @@ public function Commit()
/**
* @test
- * @expectedException \PDOException
- * @expectedExceptionMessage There is no active transaction
*/
public function WithoutTransaction_RollBack_ThrowException()
{
+ $this->expectException(\PDOException::class);
+ $this->expectExceptionMessage('There is no active transaction');
+
$this->transaction->rollBack();
}
@@ -76,7 +78,7 @@ public function RollBack()
$this->assertFalse($this->transaction->isTransactionActive());
}
- protected function setUp()
+ protected function setUp(): void
{
$this->pdo = new \PDO('sqlite::memory:');
$this->transaction = new PDOTransactionAdapter($this->pdo);
diff --git a/tests/OpenClassrooms/UseCase/BusinessRules/Entities/PaginatedCollectionBuilderTest.php b/tests/OpenClassrooms/UseCase/BusinessRules/Entities/PaginatedCollectionBuilderTest.php
index c8fcaeb..eb6d102 100644
--- a/tests/OpenClassrooms/UseCase/BusinessRules/Entities/PaginatedCollectionBuilderTest.php
+++ b/tests/OpenClassrooms/UseCase/BusinessRules/Entities/PaginatedCollectionBuilderTest.php
@@ -5,11 +5,12 @@
use OpenClassrooms\UseCase\Application\Entity\PaginatedCollectionBuilderImpl;
use OpenClassrooms\UseCase\Application\Entity\PaginatedCollectionImpl;
use OpenClassrooms\UseCase\BusinessRules\Entities\PaginatedCollectionBuilder;
+use PHPUnit\Framework\TestCase;
/**
* @author Romain Kuzniak
*/
-class PaginatedCollectionBuilderTest extends \PHPUnit_Framework_TestCase
+class PaginatedCollectionBuilderTest extends TestCase
{
/**
@@ -49,7 +50,7 @@ public function ReturnPaginatedCollection()
$this->assertEquals(2, $paginatedCollection->getTotalPages());
}
- protected function setUp()
+ protected function setUp(): void
{
$this->builder = new PaginatedCollectionBuilderImpl();
}
diff --git a/tests/OpenClassrooms/UseCase/BusinessRules/Entities/PaginatedCollectionTest.php b/tests/OpenClassrooms/UseCase/BusinessRules/Entities/PaginatedCollectionTest.php
index 583bc30..b6abce7 100644
--- a/tests/OpenClassrooms/UseCase/BusinessRules/Entities/PaginatedCollectionTest.php
+++ b/tests/OpenClassrooms/UseCase/BusinessRules/Entities/PaginatedCollectionTest.php
@@ -3,11 +3,12 @@
namespace OpenClassrooms\Tests\UseCase\BusinessRules\Entities;
use OpenClassrooms\UseCase\Application\Entity\PaginatedCollectionImpl;
+use PHPUnit\Framework\TestCase;
/**
* @author Romain Kuzniak
*/
-class PaginatedCollectionTest extends \PHPUnit_Framework_TestCase
+class PaginatedCollectionTest extends TestCase
{
/**
* @test
diff --git a/tests/OpenClassrooms/UseCase/BusinessRules/Responders/PaginatedUseCaseResponseBuilderTest.php b/tests/OpenClassrooms/UseCase/BusinessRules/Responders/PaginatedUseCaseResponseBuilderTest.php
index de62749..cf65d23 100644
--- a/tests/OpenClassrooms/UseCase/BusinessRules/Responders/PaginatedUseCaseResponseBuilderTest.php
+++ b/tests/OpenClassrooms/UseCase/BusinessRules/Responders/PaginatedUseCaseResponseBuilderTest.php
@@ -4,11 +4,12 @@
use OpenClassrooms\Tests\UseCase\BusinessRules\Responders\Doubles\PaginatedUseCaseResponseBuilderStub;
use OpenClassrooms\UseCase\BusinessRules\Responders\PaginatedUseCaseResponseBuilder;
+use PHPUnit\Framework\TestCase;
/**
* @author Romain Kuzniak
*/
-class PaginatedUseCaseResponseBuilderTest extends \PHPUnit_Framework_TestCase
+class PaginatedUseCaseResponseBuilderTest extends TestCase
{
/**
@@ -114,7 +115,7 @@ public function ReturnResponse()
$this->assertEquals(10, $paginatedUseCaseResponse->getTotalPages());
}
- protected function setUp()
+ protected function setUp(): void
{
$this->builder = new PaginatedUseCaseResponseBuilderStub();
}
diff --git a/tests/OpenClassrooms/UseCase/BusinessRules/Responders/PaginatedUseCaseResponseFactoryTest.php b/tests/OpenClassrooms/UseCase/BusinessRules/Responders/PaginatedUseCaseResponseFactoryTest.php
index bc47e74..c558e21 100644
--- a/tests/OpenClassrooms/UseCase/BusinessRules/Responders/PaginatedUseCaseResponseFactoryTest.php
+++ b/tests/OpenClassrooms/UseCase/BusinessRules/Responders/PaginatedUseCaseResponseFactoryTest.php
@@ -6,11 +6,12 @@
use OpenClassrooms\UseCase\Application\Entity\PaginatedCollectionImpl;
use OpenClassrooms\UseCase\Application\Responder\PaginatedUseCaseResponseFactoryImpl;
use OpenClassrooms\UseCase\BusinessRules\Responders\PaginatedUseCaseResponseFactory;
+use PHPUnit\Framework\TestCase;
/**
* @author Romain Kuzniak
*/
-class PaginatedUseCaseResponseFactoryTest extends \PHPUnit_Framework_TestCase
+class PaginatedUseCaseResponseFactoryTest extends TestCase
{
/**
@@ -55,7 +56,7 @@ public function WithPaginatedCollection_CreateFromPaginatedCollection_ReturnResp
$this->assertEquals(2, $response->getTotalPages());
}
- protected function setUp()
+ protected function setUp(): void
{
$this->factory = new PaginatedUseCaseResponseFactoryImpl();
$this->factory->setPaginatedUseCaseResponseBuilder(new PaginatedUseCaseResponseBuilderStub());
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index 69948a4..ff94591 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -3,13 +3,8 @@
namespace OpenClassrooms\Tests;
use Composer\Autoload\ClassLoader;
-use Doctrine\Common\Annotations\AnnotationRegistry;
error_reporting(E_ALL | E_STRICT);
/** @var ClassLoader $loader */
require __DIR__.'/../vendor/autoload.php';
-AnnotationRegistry::registerAutoloadNamespace(
- 'OpenClassrooms\UseCase\Application\Annotations',
- dirname(__DIR__).'/src'
-);