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;
class TestWorker
{
public $id = 1;
}
class PoolTest extends \PHPUnit_Framework_TestCase
{
public function testPool()
{
$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

@@ -40,7 +40,7 @@ class MemoryStorage implements Storage
*/
public function delete($id)
{
if(!isset($this->data[$id])){
if (!isset($this->data[$id])) {
return false;
}
@@ -49,6 +49,4 @@ class MemoryStorage implements Storage
return true;
}
}

View File

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

View File

@@ -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());
}
}
}

View File

@@ -38,4 +38,4 @@ interface Storage
* @return bool
*/
public function delete($id);
}
}

View File

@@ -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')
);
}
}