mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-03 13:37:27 +02:00
it was created the Structural namespace and append its patterns
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Tests\Adapter;
|
namespace DesignPatterns\Structural\Adapter;
|
||||||
|
|
||||||
use DesignPatterns\Adapter\EBookAdapter;
|
use DesignPatterns\Structural\Adapter\EBookAdapter;
|
||||||
use DesignPatterns\Adapter\Kindle;
|
use DesignPatterns\Structural\Adapter\Kindle;
|
||||||
use DesignPatterns\Adapter\PaperBookInterface;
|
use DesignPatterns\Structural\Adapter\PaperBookInterface;
|
||||||
use DesignPatterns\Adapter\Book;
|
use DesignPatterns\Structural\Adapter\Book;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AdapterTest shows the use of an adapted e-book that behave like a book
|
* AdapterTest shows the use of an adapted e-book that behave like a book
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Adapter;
|
namespace DesignPatterns\Structural\Adapter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Book is a concrete and standard paper book
|
* Book is a concrete and standard paper book
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Adapter;
|
namespace DesignPatterns\Structural\Adapter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* EBookAdapter is an adapter to fit an e-book like a paper book
|
* EBookAdapter is an adapter to fit an e-book like a paper book
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Adapter;
|
namespace DesignPatterns\Structural\Adapter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* EBookInterface is a contract for an electronic book
|
* EBookInterface is a contract for an electronic book
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Adapter;
|
namespace DesignPatterns\Structural\Adapter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Kindle is a concrete electronic book
|
* Kindle is a concrete electronic book
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Adapter;
|
namespace DesignPatterns\Structural\Adapter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PaperBookInterface is a contract for a book
|
* PaperBookInterface is a contract for a book
|
||||||
|
@@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
namespace DesignPatterns\Test\Composite;
|
namespace DesignPatterns\Test\Composite;
|
||||||
|
|
||||||
use DesignPatterns\Composite;
|
use DesignPatterns\Structural\Composite;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FormTest tests the composite pattern on Form
|
* FormTest tests the composite pattern on Form
|
||||||
*/
|
*/
|
||||||
class FormTest extends \PHPUnit_Framework_TestCase
|
class CompositeTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
public function testRender()
|
public function testRender()
|
||||||
@@ -29,6 +29,6 @@ class FormTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testFormImplementsFormEelement()
|
public function testFormImplementsFormEelement()
|
||||||
{
|
{
|
||||||
$this->assertTrue(is_subclass_of('DesignPatterns\Composite\Form', 'DesignPatterns\Composite\FormElement'));
|
$this->assertTrue(is_subclass_of('DesignPatterns\Structural\Composite\Form', 'DesignPatterns\Structural\Composite\FormElement'));
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Composite;
|
namespace DesignPatterns\Structural\Composite;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The composite node MUST extend the component contract. This is mandatory for building
|
* The composite node MUST extend the component contract. This is mandatory for building
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Composite;
|
namespace DesignPatterns\Structural\Composite;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class FormElement
|
* Class FormElement
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Composite;
|
namespace DesignPatterns\Structural\Composite;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class InputElement
|
* Class InputElement
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Composite;
|
namespace DesignPatterns\Structural\Composite;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class TextElement
|
* Class TextElement
|
||||||
|
@@ -1,14 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Test\DataMapper;
|
namespace DesignPatterns\Structural\DataMapper;
|
||||||
|
|
||||||
use DesignPatterns\DataMapper\UserMapper;
|
use DesignPatterns\Structural\DataMapper\UserMapper;
|
||||||
use DesignPatterns\DataMapper\User;
|
use DesignPatterns\Structural\DataMapper\User;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UserMapperTest tests the datamapper pattern
|
* UserMapperTest tests the datamapper pattern
|
||||||
*/
|
*/
|
||||||
class UserMapperTest extends \PHPUnit_Framework_TestCase
|
class DataMapperTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var UserMapper
|
* @var UserMapper
|
||||||
@@ -22,7 +22,7 @@ class UserMapperTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
$this->dbal = $this->getMockBuilder('DesignPatterns\DataMapper\DBAL')
|
$this->dbal = $this->getMockBuilder('DesignPatterns\Structural\DataMapper\DBAL')
|
||||||
->disableAutoload()
|
->disableAutoload()
|
||||||
->setMethods(array('insert', 'update', 'find', 'findAll'))
|
->setMethods(array('insert', 'update', 'find', 'findAll'))
|
||||||
->getMock();
|
->getMock();
|
||||||
@@ -90,7 +90,7 @@ class UserMapperTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException InvalidArgumentException
|
* @expectedException \InvalidArgumentException
|
||||||
* @expectedExceptionMessage User #404 not found
|
* @expectedExceptionMessage User #404 not found
|
||||||
*/
|
*/
|
||||||
public function testNotFound()
|
public function testNotFound()
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\DataMapper;
|
namespace DesignPatterns\Structural\DataMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DataMapper pattern
|
* DataMapper pattern
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\DataMapper;
|
namespace DesignPatterns\Structural\DataMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* class UserMapper
|
* class UserMapper
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Decorator;
|
namespace DesignPatterns\Structural\Decorator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the Decorator MUST implement the RendererInterface contract, this is the key-feature
|
* the Decorator MUST implement the RendererInterface contract, this is the key-feature
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Tests\Decorator;
|
namespace DesignPatterns\Structural\Decorator;
|
||||||
|
|
||||||
use DesignPatterns\Decorator;
|
use DesignPatterns\Structural\Decorator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DecoratorTest tests the decorator pattern
|
* DecoratorTest tests the decorator pattern
|
||||||
@@ -38,7 +38,7 @@ class DecoratorTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testDecoratorMustImplementsRenderer()
|
public function testDecoratorMustImplementsRenderer()
|
||||||
{
|
{
|
||||||
$this->assertTrue(is_subclass_of('DesignPatterns\Decorator\Decorator', 'DesignPatterns\Decorator\RendererInterface'));
|
$this->assertTrue(is_subclass_of('DesignPatterns\Structural\Decorator\Decorator', 'DesignPatterns\Structural\Decorator\RendererInterface'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -48,7 +48,7 @@ class DecoratorTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testDecoratorTypeHinted()
|
public function testDecoratorTypeHinted()
|
||||||
{
|
{
|
||||||
$this->getMockForAbstractClass('DesignPatterns\Decorator\Decorator', array(new \stdClass()));
|
$this->getMockForAbstractClass('DesignPatterns\Structural\Decorator\Decorator', array(new \stdClass()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -56,8 +56,8 @@ class DecoratorTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testDecoratorOnlyAcceptRenderer()
|
public function testDecoratorOnlyAcceptRenderer()
|
||||||
{
|
{
|
||||||
$mock = $this->getMock('DesignPatterns\Decorator\RendererInterface');
|
$mock = $this->getMock('DesignPatterns\Structural\Decorator\RendererInterface');
|
||||||
$dec = $this->getMockForAbstractClass('DesignPatterns\Decorator\Decorator', array($mock));
|
$dec = $this->getMockForAbstractClass('DesignPatterns\Structural\Decorator\Decorator', array($mock));
|
||||||
$this->assertNotNull($dec);
|
$this->assertNotNull($dec);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Decorator;
|
namespace DesignPatterns\Structural\Decorator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class RenderInJson
|
* Class RenderInJson
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Decorator;
|
namespace DesignPatterns\Structural\Decorator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class RenderInXml
|
* Class RenderInXml
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Decorator;
|
namespace DesignPatterns\Structural\Decorator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class RendererInterface
|
* Class RendererInterface
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Decorator;
|
namespace DesignPatterns\Structural\Decorator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Webservice
|
* Class Webservice
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\DependencyInjection;
|
namespace DesignPatterns\Structural\DependencyInjection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* class AbstractConfig
|
* class AbstractConfig
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\DependencyInjection;
|
namespace DesignPatterns\Structural\DependencyInjection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* class ArrayConfig
|
* class ArrayConfig
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\DependencyInjection;
|
namespace DesignPatterns\Structural\DependencyInjection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Connection
|
* Class Connection
|
||||||
|
@@ -1,11 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Tests\DependencyInjection;
|
namespace DesignPatterns\Structural\DependencyInjection;
|
||||||
|
|
||||||
use DesignPatterns\DependencyInjection\Parameters;
|
use DesignPatterns\Structural\DependencyInjection\Parameters;
|
||||||
use DesignPatterns\DependencyInjection\AbstractConfig;
|
use DesignPatterns\Structural\DependencyInjection\AbstractConfig;
|
||||||
use DesignPatterns\DependencyInjection\ArrayConfig;
|
use DesignPatterns\Structural\DependencyInjection\ArrayConfig;
|
||||||
use DesignPatterns\DependencyInjection\Connection;
|
use DesignPatterns\Structural\DependencyInjection\Connection;
|
||||||
|
|
||||||
class DependencyInjectionTest extends \PHPUnit_Framework_TestCase
|
class DependencyInjectionTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\DependencyInjection;
|
namespace DesignPatterns\Structural\DependencyInjection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parameters interface
|
* Parameters interface
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Facade;
|
namespace DesignPatterns\Structural\Facade;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class BiosInterface
|
* Class BiosInterface
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Facade;
|
namespace DesignPatterns\Structural\Facade;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Tests\Facade;
|
namespace DesignPatterns\Structural\Facade;
|
||||||
|
|
||||||
use DesignPatterns\Facade\Facade as Computer;
|
use DesignPatterns\Structural\Facade\Facade as Computer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FacadeTest shows example of facades
|
* FacadeTest shows example of facades
|
||||||
@@ -12,11 +12,11 @@ class FacadeTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function getComputer()
|
public function getComputer()
|
||||||
{
|
{
|
||||||
$bios = $this->getMockBuilder('DesignPatterns\Facade\BiosInterface')
|
$bios = $this->getMockBuilder('DesignPatterns\Structural\Facade\BiosInterface')
|
||||||
->setMethods(array('launch', 'execute', 'waitForKeyPress'))
|
->setMethods(array('launch', 'execute', 'waitForKeyPress'))
|
||||||
->disableAutoload()
|
->disableAutoload()
|
||||||
->getMock();
|
->getMock();
|
||||||
$operatingSys = $this->getMockBuilder('DesignPatterns\Facade\OsInterface')
|
$operatingSys = $this->getMockBuilder('DesignPatterns\Structural\Facade\OsInterface')
|
||||||
->setMethods(array('getName'))
|
->setMethods(array('getName'))
|
||||||
->disableAutoload()
|
->disableAutoload()
|
||||||
->getMock();
|
->getMock();
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Facade;
|
namespace DesignPatterns\Structural\Facade;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class OsInterface
|
* Class OsInterface
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Tests\FluentInterface;
|
namespace DesignPatterns\Structural\FluentInterface;
|
||||||
|
|
||||||
use DesignPatterns\FluentInterface\SQL;
|
use DesignPatterns\Structural\FluentInterface\Sql;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FluentInterfaceTest tests the fluent interface SQL
|
* FluentInterfaceTest tests the fluent interface SQL
|
||||||
@@ -12,7 +12,7 @@ class FluentInterfaceTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testBuildSQL()
|
public function testBuildSQL()
|
||||||
{
|
{
|
||||||
$instance = new SQL();
|
$instance = new Sql();
|
||||||
$query = $instance->select(array('foo', 'bar'))
|
$query = $instance->select(array('foo', 'bar'))
|
||||||
->from('foobar', 'f')
|
->from('foobar', 'f')
|
||||||
->where('f.bar = ?')
|
->where('f.bar = ?')
|
@@ -1,11 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\FluentInterface;
|
namespace DesignPatterns\Structural\FluentInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* class SQL
|
* class SQL
|
||||||
*/
|
*/
|
||||||
class SQL
|
class Sql
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Proxy;
|
namespace DesignPatterns\Structural\Proxy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* class Record
|
* class Record
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Proxy;
|
namespace DesignPatterns\Structural\Proxy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class RecordProxy
|
* Class RecordProxy
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Registry;
|
namespace DesignPatterns\Structural\Registry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* class Registry
|
* class Registry
|
||||||
|
17
Structural/Registry/RegistryTest.php
Normal file
17
Structural/Registry/RegistryTest.php
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace DesignPatterns\Structural\Registry;
|
||||||
|
|
||||||
|
use DesignPatterns\Structural\Registry\Registry;
|
||||||
|
|
||||||
|
class RegistryTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
public function testSetAndGetLogger()
|
||||||
|
{
|
||||||
|
Registry::set(Registry::LOGGER, new \StdClass());
|
||||||
|
|
||||||
|
$logger = Registry::get(Registry::LOGGER);
|
||||||
|
$this->assertInstanceOf('StdClass', $logger);
|
||||||
|
}
|
||||||
|
}
|
@@ -1,9 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use DesignPatterns\Registry\Registry;
|
|
||||||
|
|
||||||
// while bootstrapping the application
|
|
||||||
Registry::set(Registry::LOGGER, new \StdClass());
|
|
||||||
|
|
||||||
// throughout the application
|
|
||||||
Registry::get(Registry::LOGGER)->log('foo');
|
|
Reference in New Issue
Block a user