Merge pull request #111 from jcherqui/master

Validation PSR2
This commit is contained in:
Dominik Liebler
2014-11-05 18:04:46 +01:00
7 changed files with 103 additions and 40 deletions

View File

@@ -4,14 +4,8 @@ namespace DesignPatterns\Creational\Pool\Tests;
use DesignPatterns\Creational\Pool\Pool; use DesignPatterns\Creational\Pool\Pool;
class TestWorker
{
public $id = 1;
}
class PoolTest extends \PHPUnit_Framework_TestCase class PoolTest extends \PHPUnit_Framework_TestCase
{ {
public function testPool() public function testPool()
{ {
$pool = new Pool('DesignPatterns\Creational\Pool\Tests\TestWorker'); $pool = new Pool('DesignPatterns\Creational\Pool\Tests\TestWorker');

View File

@@ -0,0 +1,8 @@
<?php
namespace DesignPatterns\Creational\Pool\Tests;
class TestWorker
{
public $id = 1;
}

View File

@@ -49,6 +49,4 @@ class MemoryStorage implements Storage
return true; return true;
} }
} }

View File

@@ -1,6 +1,7 @@
<?php <?php
namespace DesignPatterns\Repository; namespace DesignPatterns\Repository;
/** /**
* Post represents entity for some post that user left on the site * Post represents entity for some post that user left on the site
* *
@@ -34,9 +35,6 @@ class Post
*/ */
private $created; private $created;
/** /**
* @param int $id * @param int $id
*/ */
@@ -116,7 +114,4 @@ class Post
{ {
return $this->title; return $this->title;
} }
} }

View File

@@ -5,8 +5,12 @@ namespace DesignPatterns\Repository;
/** /**
* Repository for class Post * Repository for class Post
* This class is between Entity layer(class Post) and access object layer(interface Storage) * 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 * Class PostRepository
* @package DesignPatterns\Repository * @package DesignPatterns\Repository

View File

@@ -33,8 +33,15 @@ class ServiceLocatorTest extends TestCase
public function testHasServices() public function testHasServices()
{ {
$this->serviceLocator->add('DesignPatterns\More\ServiceLocator\LogServiceInterface', $this->logService); $this->serviceLocator->add(
$this->serviceLocator->add('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface', $this->databaseService); '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\LogServiceInterface'));
$this->assertTrue($this->serviceLocator->has('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface')); $this->assertTrue($this->serviceLocator->has('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface'));
@@ -44,35 +51,92 @@ class ServiceLocatorTest extends TestCase
public function testServicesWithObject() public function testServicesWithObject()
{ {
$this->serviceLocator->add('DesignPatterns\More\ServiceLocator\LogServiceInterface', $this->logService); $this->serviceLocator->add(
$this->serviceLocator->add('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface', $this->databaseService); 'DesignPatterns\More\ServiceLocator\LogServiceInterface',
$this->logService
);
$this->assertSame($this->logService, $this->serviceLocator->get('DesignPatterns\More\ServiceLocator\LogServiceInterface')); $this->serviceLocator->add(
$this->assertSame($this->databaseService, $this->serviceLocator->get('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface')); '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() public function testServicesWithClass()
{ {
$this->serviceLocator $this->serviceLocator->add(
->add('DesignPatterns\More\ServiceLocator\LogServiceInterface', get_class($this->logService)); 'DesignPatterns\More\ServiceLocator\LogServiceInterface',
$this->serviceLocator->add('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface', get_class($this->databaseService)); get_class($this->logService)
);
$this->assertNotSame($this->logService, $this->serviceLocator->get('DesignPatterns\More\ServiceLocator\LogServiceInterface')); $this->serviceLocator->add(
$this->assertInstanceOf('DesignPatterns\More\ServiceLocator\LogServiceInterface', $this->serviceLocator->get('DesignPatterns\More\ServiceLocator\LogServiceInterface')); 'DesignPatterns\More\ServiceLocator\DatabaseServiceInterface',
get_class($this->databaseService)
);
$this->assertNotSame($this->databaseService, $this->serviceLocator->get('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface')); $this->assertNotSame(
$this->assertInstanceOf('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface', $this->serviceLocator->get('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface')); $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() public function testServicesNotShared()
{ {
$this->serviceLocator->add('DesignPatterns\More\ServiceLocator\LogServiceInterface', $this->logService, false); $this->serviceLocator->add(
$this->serviceLocator->add('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface', $this->databaseService, false); 'DesignPatterns\More\ServiceLocator\LogServiceInterface',
$this->logService,
false
);
$this->assertNotSame($this->logService, $this->serviceLocator->get('DesignPatterns\More\ServiceLocator\LogServiceInterface')); $this->serviceLocator->add(
$this->assertInstanceOf('DesignPatterns\More\ServiceLocator\LogServiceInterface', $this->serviceLocator->get('DesignPatterns\More\ServiceLocator\LogServiceInterface')); 'DesignPatterns\More\ServiceLocator\DatabaseServiceInterface',
$this->databaseService,
false
);
$this->assertNotSame($this->databaseService, $this->serviceLocator->get('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface')); $this->assertNotSame(
$this->assertInstanceOf('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface', $this->serviceLocator->get('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface')); $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')
);
} }
} }