Skip to content

Validation PSR2 #111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 5, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions Creational/Pool/Tests/PoolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,8 @@

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');
Expand Down
8 changes: 8 additions & 0 deletions Creational/Pool/Tests/TestWorker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace DesignPatterns\Creational\Pool\Tests;

class TestWorker
{
public $id = 1;
}
4 changes: 1 addition & 3 deletions More/Repository/MemoryStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function retrieve($id)
*/
public function delete($id)
{
if(!isset($this->data[$id])){
if (!isset($this->data[$id])) {
return false;
}

Expand All @@ -49,6 +49,4 @@ public function delete($id)

return true;
}

}

9 changes: 2 additions & 7 deletions More/Repository/Post.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

namespace DesignPatterns\Repository;

/**
* Post represents entity for some post that user left on the site
*
Expand Down Expand Up @@ -34,9 +35,6 @@ class Post
*/
private $created;




/**
* @param int $id
*/
Expand Down Expand Up @@ -116,7 +114,4 @@ public function getTitle()
{
return $this->title;
}



}
}
12 changes: 8 additions & 4 deletions More/Repository/PostRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
/**
* 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
Expand All @@ -29,7 +33,7 @@ public function __construct(Storage $persistence)
public function getById($id)
{
$arrayData = $this->persistence->retrieve($id);
if(is_null($arrayData)){
if (is_null($arrayData)) {
return null;
}

Expand Down Expand Up @@ -72,4 +76,4 @@ public function delete(Post $post)
{
return $this->persistence->delete($post->getId());
}
}
}
2 changes: 1 addition & 1 deletion More/Repository/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ public function retrieve($id);
* @return bool
*/
public function delete($id);
}
}
112 changes: 88 additions & 24 deletions More/ServiceLocator/Tests/ServiceLocatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,15 @@ public function setUp()

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'));
Expand All @@ -44,35 +51,92 @@ public function testHasServices()

public function testServicesWithObject()
{
$this->serviceLocator->add('DesignPatterns\More\ServiceLocator\LogServiceInterface', $this->logService);
$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'));
$this->serviceLocator->add(
'DesignPatterns\More\ServiceLocator\LogServiceInterface',
$this->logService
);

$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->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'));
$this->serviceLocator->add(
'DesignPatterns\More\ServiceLocator\LogServiceInterface',
get_class($this->logService)
);

$this->serviceLocator->add(
'DesignPatterns\More\ServiceLocator\DatabaseServiceInterface',
get_class($this->databaseService)
);

$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->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'));
$this->serviceLocator->add(
'DesignPatterns\More\ServiceLocator\LogServiceInterface',
$this->logService,
false
);

$this->serviceLocator->add(
'DesignPatterns\More\ServiceLocator\DatabaseServiceInterface',
$this->databaseService,
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->assertNotSame(
$this->databaseService,
$this->serviceLocator->get('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface')
);

$this->assertInstanceOf(
'DesignPatterns\More\ServiceLocator\DatabaseServiceInterface',
$this->serviceLocator->get('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface')
);
}
}