From d5b96d139f38447071a5d97510a4246aa3ca4989 Mon Sep 17 00:00:00 2001 From: jcherqui Date: Wed, 5 Nov 2014 10:24:19 +0100 Subject: [PATCH] Validation PSR2 --- Creational/Pool/Tests/PoolTest.php | 6 -- Creational/Pool/Tests/TestWorker.php | 8 ++ More/Repository/MemoryStorage.php | 4 +- More/Repository/Post.php | 9 +- More/Repository/PostRepository.php | 12 ++- More/Repository/Storage.php | 2 +- .../Tests/ServiceLocatorTest.php | 102 ++++++++++++++---- 7 files changed, 103 insertions(+), 40 deletions(-) create mode 100644 Creational/Pool/Tests/TestWorker.php diff --git a/Creational/Pool/Tests/PoolTest.php b/Creational/Pool/Tests/PoolTest.php index 00e0975..7ff546a 100644 --- a/Creational/Pool/Tests/PoolTest.php +++ b/Creational/Pool/Tests/PoolTest.php @@ -4,14 +4,8 @@ namespace DesignPatterns\Creational\Pool\Tests; use DesignPatterns\Creational\Pool\Pool; -class TestWorker -{ - public $id = 1; -} - class PoolTest extends \PHPUnit_Framework_TestCase { - public function testPool() { $pool = new Pool('DesignPatterns\Creational\Pool\Tests\TestWorker'); diff --git a/Creational/Pool/Tests/TestWorker.php b/Creational/Pool/Tests/TestWorker.php new file mode 100644 index 0000000..7c2c2db --- /dev/null +++ b/Creational/Pool/Tests/TestWorker.php @@ -0,0 +1,8 @@ +data[$id])){ + if (!isset($this->data[$id])) { return false; } @@ -49,6 +49,4 @@ class MemoryStorage implements Storage return true; } - } - diff --git a/More/Repository/Post.php b/More/Repository/Post.php index 5308bb0..227daaf 100644 --- a/More/Repository/Post.php +++ b/More/Repository/Post.php @@ -1,6 +1,7 @@ title; } - - - -} \ No newline at end of file +} diff --git a/More/Repository/PostRepository.php b/More/Repository/PostRepository.php index e6c880b..3feeffa 100644 --- a/More/Repository/PostRepository.php +++ b/More/Repository/PostRepository.php @@ -5,8 +5,12 @@ namespace DesignPatterns\Repository; /** * Repository for class Post * This class is between Entity layer(class Post) and access object layer(interface Storage) - * Repository encapsulates the set of objects persisted in a data store and the operations performed over them, providing a more object-oriented view of the persistence layer - * Repository also supports the objective of achieving a clean separation and one-way dependency between the domain and data mapping layers + * + * Repository encapsulates the set of objects persisted in a data store and the operations performed over them + * providing a more object-oriented view of the persistence layer + * + * Repository also supports the objective of achieving a clean separation and one-way dependency + * between the domain and data mapping layers * * Class PostRepository * @package DesignPatterns\Repository @@ -29,7 +33,7 @@ class PostRepository public function getById($id) { $arrayData = $this->persistence->retrieve($id); - if(is_null($arrayData)){ + if (is_null($arrayData)) { return null; } @@ -72,4 +76,4 @@ class PostRepository { return $this->persistence->delete($post->getId()); } -} \ No newline at end of file +} diff --git a/More/Repository/Storage.php b/More/Repository/Storage.php index 7ed8589..58313b0 100644 --- a/More/Repository/Storage.php +++ b/More/Repository/Storage.php @@ -38,4 +38,4 @@ interface Storage * @return bool */ public function delete($id); -} \ No newline at end of file +} diff --git a/More/ServiceLocator/Tests/ServiceLocatorTest.php b/More/ServiceLocator/Tests/ServiceLocatorTest.php index 14e5974..d6b7ef6 100644 --- a/More/ServiceLocator/Tests/ServiceLocatorTest.php +++ b/More/ServiceLocator/Tests/ServiceLocatorTest.php @@ -33,8 +33,15 @@ class ServiceLocatorTest extends TestCase public function testHasServices() { - $this->serviceLocator->add('DesignPatterns\More\ServiceLocator\LogServiceInterface', $this->logService); - $this->serviceLocator->add('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface', $this->databaseService); + $this->serviceLocator->add( + 'DesignPatterns\More\ServiceLocator\LogServiceInterface', + $this->logService + ); + + $this->serviceLocator->add( + 'DesignPatterns\More\ServiceLocator\DatabaseServiceInterface', + $this->databaseService + ); $this->assertTrue($this->serviceLocator->has('DesignPatterns\More\ServiceLocator\LogServiceInterface')); $this->assertTrue($this->serviceLocator->has('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface')); @@ -44,35 +51,92 @@ class ServiceLocatorTest extends TestCase public function testServicesWithObject() { - $this->serviceLocator->add('DesignPatterns\More\ServiceLocator\LogServiceInterface', $this->logService); - $this->serviceLocator->add('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface', $this->databaseService); + $this->serviceLocator->add( + 'DesignPatterns\More\ServiceLocator\LogServiceInterface', + $this->logService + ); - $this->assertSame($this->logService, $this->serviceLocator->get('DesignPatterns\More\ServiceLocator\LogServiceInterface')); - $this->assertSame($this->databaseService, $this->serviceLocator->get('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface')); + $this->serviceLocator->add( + 'DesignPatterns\More\ServiceLocator\DatabaseServiceInterface', + $this->databaseService + ); + + $this->assertSame( + $this->logService, + $this->serviceLocator->get('DesignPatterns\More\ServiceLocator\LogServiceInterface') + ); + + $this->assertSame( + $this->databaseService, + $this->serviceLocator->get('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface') + ); } public function testServicesWithClass() { - $this->serviceLocator - ->add('DesignPatterns\More\ServiceLocator\LogServiceInterface', get_class($this->logService)); - $this->serviceLocator->add('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface', get_class($this->databaseService)); + $this->serviceLocator->add( + 'DesignPatterns\More\ServiceLocator\LogServiceInterface', + get_class($this->logService) + ); - $this->assertNotSame($this->logService, $this->serviceLocator->get('DesignPatterns\More\ServiceLocator\LogServiceInterface')); - $this->assertInstanceOf('DesignPatterns\More\ServiceLocator\LogServiceInterface', $this->serviceLocator->get('DesignPatterns\More\ServiceLocator\LogServiceInterface')); + $this->serviceLocator->add( + 'DesignPatterns\More\ServiceLocator\DatabaseServiceInterface', + get_class($this->databaseService) + ); - $this->assertNotSame($this->databaseService, $this->serviceLocator->get('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface')); - $this->assertInstanceOf('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface', $this->serviceLocator->get('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface')); + $this->assertNotSame( + $this->logService, + $this->serviceLocator->get('DesignPatterns\More\ServiceLocator\LogServiceInterface') + ); + + $this->assertInstanceOf( + 'DesignPatterns\More\ServiceLocator\LogServiceInterface', + $this->serviceLocator->get('DesignPatterns\More\ServiceLocator\LogServiceInterface') + ); + + $this->assertNotSame( + $this->databaseService, + $this->serviceLocator->get('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface') + ); + + $this->assertInstanceOf( + 'DesignPatterns\More\ServiceLocator\DatabaseServiceInterface', + $this->serviceLocator->get('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface') + ); } public function testServicesNotShared() { - $this->serviceLocator->add('DesignPatterns\More\ServiceLocator\LogServiceInterface', $this->logService, false); - $this->serviceLocator->add('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface', $this->databaseService, false); + $this->serviceLocator->add( + 'DesignPatterns\More\ServiceLocator\LogServiceInterface', + $this->logService, + false + ); - $this->assertNotSame($this->logService, $this->serviceLocator->get('DesignPatterns\More\ServiceLocator\LogServiceInterface')); - $this->assertInstanceOf('DesignPatterns\More\ServiceLocator\LogServiceInterface', $this->serviceLocator->get('DesignPatterns\More\ServiceLocator\LogServiceInterface')); + $this->serviceLocator->add( + 'DesignPatterns\More\ServiceLocator\DatabaseServiceInterface', + $this->databaseService, + false + ); - $this->assertNotSame($this->databaseService, $this->serviceLocator->get('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface')); - $this->assertInstanceOf('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface', $this->serviceLocator->get('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface')); + $this->assertNotSame( + $this->logService, + $this->serviceLocator->get('DesignPatterns\More\ServiceLocator\LogServiceInterface') + ); + + $this->assertInstanceOf( + 'DesignPatterns\More\ServiceLocator\LogServiceInterface', + $this->serviceLocator->get('DesignPatterns\More\ServiceLocator\LogServiceInterface') + ); + + $this->assertNotSame( + $this->databaseService, + $this->serviceLocator->get('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface') + ); + + $this->assertInstanceOf( + 'DesignPatterns\More\ServiceLocator\DatabaseServiceInterface', + $this->serviceLocator->get('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface') + ); } }