it was created the Behavioral namespace and append its patterns

This commit is contained in:
Antonio Spinelli
2014-04-15 22:25:48 -03:00
parent 2f7837927f
commit 646e0e2fd9
47 changed files with 88 additions and 77 deletions

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace DesignPatterns\Behavioral\Tests\ChainOfResponsibilities; namespace DesignPatterns\Behavioral\ChainOfResponsibilities;
use DesignPatterns\Behavioral\ChainOfResponsibilities\Request; use DesignPatterns\Behavioral\ChainOfResponsibilities\Request;
use DesignPatterns\Behavioral\ChainOfResponsibilities\Responsible\FastStorage; use DesignPatterns\Behavioral\ChainOfResponsibilities\Responsible\FastStorage;

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace DesignPatterns\Behavioral\Command\Tests; namespace DesignPatterns\Behavioral\Command;
use DesignPatterns\Behavioral\Command\Invoker; use DesignPatterns\Behavioral\Command\Invoker;
use DesignPatterns\Behavioral\Command\Receiver; use DesignPatterns\Behavioral\Command\Receiver;

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace DesignPatterns\Behavioral\Iterator\Tests; namespace DesignPatterns\Behavioral\Iterator;
use DesignPatterns\Behavioral\Iterator\Book; use DesignPatterns\Behavioral\Iterator\Book;
use DesignPatterns\Behavioral\Iterator\BookList; use DesignPatterns\Behavioral\Iterator\BookList;

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace DesignPatterns\Mediator; namespace DesignPatterns\Behavioral\Mediator;
/** /**
* Colleague is an abstract colleague who works together but he only knows * Colleague is an abstract colleague who works together but he only knows

View File

@@ -1,20 +1,29 @@
<?php <?php
namespace DesignPatterns\Mediator; namespace DesignPatterns\Behavioral\Mediator;
use DesignPatterns\Mediator\Subsystem; use DesignPatterns\Behavioral\Mediator\Subsystem;
/** /**
* Mediator is the concrete Mediator for this design pattern. * Mediator is the concrete Mediator for this design pattern.
*
* In this example, I have made a "Hello World" with the Mediator Pattern. * In this example, I have made a "Hello World" with the Mediator Pattern.
*/ */
class Mediator implements MediatorInterface class Mediator implements MediatorInterface
{ {
// you could have an array /**
* @var Subsystem\Server
*/
protected $server; protected $server;
/**
* @var Subsystem\Database
*/
protected $database; protected $database;
/**
* @var Subsystem\Client
*/
protected $client; protected $client;
/** /**
@@ -39,7 +48,6 @@ class Mediator implements MediatorInterface
/** /**
* query db * query db
*
* @return mixed * @return mixed
*/ */
public function queryDb() public function queryDb()

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace DesignPatterns\Mediator; namespace DesignPatterns\Behavioral\Mediator;
/** /**
* MediatorInterface is a contract for the Mediator * MediatorInterface is a contract for the Mediator

View File

@@ -2,10 +2,10 @@
namespace DesignPatterns\Tests\Mediator; namespace DesignPatterns\Tests\Mediator;
use DesignPatterns\Mediator\Mediator; use DesignPatterns\Behavioral\Mediator\Mediator;
use DesignPatterns\Mediator\Subsystem\Database; use DesignPatterns\Behavioral\Mediator\Subsystem\Database;
use DesignPatterns\Mediator\Subsystem\Client; use DesignPatterns\Behavioral\Mediator\Subsystem\Client;
use DesignPatterns\Mediator\Subsystem\Server; use DesignPatterns\Behavioral\Mediator\Subsystem\Server;
/** /**
* MediatorTest tests hello world * MediatorTest tests hello world

View File

@@ -1,8 +1,8 @@
<?php <?php
namespace DesignPatterns\Mediator\Subsystem; namespace DesignPatterns\Behavioral\Mediator\Subsystem;
use DesignPatterns\Mediator\Colleague; use DesignPatterns\Behavioral\Mediator\Colleague;
/** /**
* Client is a client that make request et get response * Client is a client that make request et get response

View File

@@ -1,8 +1,8 @@
<?php <?php
namespace DesignPatterns\Mediator\Subsystem; namespace DesignPatterns\Behavioral\Mediator\Subsystem;
use DesignPatterns\Mediator\Colleague; use DesignPatterns\Behavioral\Mediator\Colleague;
/** /**
* Database is a database service * Database is a database service

View File

@@ -1,8 +1,8 @@
<?php <?php
namespace DesignPatterns\Mediator\Subsystem; namespace DesignPatterns\Behavioral\Mediator\Subsystem;
use DesignPatterns\Mediator\Colleague; use DesignPatterns\Behavioral\Mediator\Colleague;
/** /**
* Server serves responses * Server serves responses

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace DesignPatterns\NullObject; namespace DesignPatterns\Behavioral\NullObject;
/** /**
* LoggerInterface is a contract for logging something * LoggerInterface is a contract for logging something

View File

@@ -1,10 +1,10 @@
<?php <?php
namespace DesignPatterns\Tests\NullObject; namespace DesignPatterns\Behavioral\NullObject;
use DesignPatterns\NullObject\NullLogger; use DesignPatterns\Behavioral\NullObject\NullLogger;
use DesignPatterns\NullObject\Service; use DesignPatterns\Behavioral\NullObject\Service;
use DesignPatterns\NullObject\PrintLogger; use DesignPatterns\Behavioral\NullObject\PrintLogger;
/** /**
* LoggerTest tests for different loggers * LoggerTest tests for different loggers
@@ -24,7 +24,7 @@ class LoggerTest extends \PHPUnit_Framework_TestCase
public function testStandardLogger() public function testStandardLogger()
{ {
$service = new Service(new PrintLogger()); $service = new Service(new PrintLogger());
$this->expectOutputString('We are in DesignPatterns\NullObject\Service::doSomething'); $this->expectOutputString('We are in DesignPatterns\Behavioral\NullObject\Service::doSomething');
$service->doSomething(); $service->doSomething();
} }
} }

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace DesignPatterns\NullObject; namespace DesignPatterns\Behavioral\NullObject;
/** /**
* Performance concerns : ok there is a call for nothing but we spare an "if is_null" * Performance concerns : ok there is a call for nothing but we spare an "if is_null"

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace DesignPatterns\NullObject; namespace DesignPatterns\Behavioral\NullObject;
/** /**
* PrintLogger is a logger that prints the log entry to standard output * PrintLogger is a logger that prints the log entry to standard output

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace DesignPatterns\NullObject; namespace DesignPatterns\Behavioral\NullObject;
/** /**
* Service is dummy service that uses a logger * Service is dummy service that uses a logger

View File

@@ -1,9 +1,9 @@
<?php <?php
namespace DesignPatterns\Tests\Observer; namespace DesignPatterns\Behavioral\Observer;
use DesignPatterns\Observer\UserObserver; use DesignPatterns\Behavioral\Observer\UserObserver;
use DesignPatterns\Observer\User; use DesignPatterns\Behavioral\Observer\User;
/** /**
* ObserverTest tests the Observer pattern * ObserverTest tests the Observer pattern
@@ -23,7 +23,7 @@ class ObserverTest extends \PHPUnit_Framework_TestCase
*/ */
public function testNotify() public function testNotify()
{ {
$this->expectOutputString('DesignPatterns\Observer\User has been updated'); $this->expectOutputString('DesignPatterns\Behavioral\Observer\User has been updated');
$subject = new User(); $subject = new User();
$subject->attach($this->observer); $subject->attach($this->observer);

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace DesignPatterns\Observer; namespace DesignPatterns\Behavioral\Observer;
/** /**
* Observer pattern : The observed object (the subject) * Observer pattern : The observed object (the subject)

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace DesignPatterns\Observer; namespace DesignPatterns\Behavioral\Observer;
/** /**
* class UserObserver * class UserObserver

View File

@@ -1,5 +1,5 @@
<?php <?php
namespace DesignPatterns\Specification; namespace DesignPatterns\Behavioral\Specification;
/** /**
* An abstract specification allows the creation of wrapped specifications * An abstract specification allows the creation of wrapped specifications

View File

@@ -1,5 +1,5 @@
<?php <?php
namespace DesignPatterns\Specification; namespace DesignPatterns\Behavioral\Specification;
/** /**
* A logical OR specification * A logical OR specification

View File

@@ -1,5 +1,5 @@
<?php <?php
namespace DesignPatterns\Specification; namespace DesignPatterns\Behavioral\Specification;
/** /**
* An trivial item * An trivial item

View File

@@ -1,5 +1,5 @@
<?php <?php
namespace DesignPatterns\Specification; namespace DesignPatterns\Behavioral\Specification;
/** /**
* A logical Not specification * A logical Not specification

View File

@@ -1,5 +1,5 @@
<?php <?php
namespace DesignPatterns\Specification; namespace DesignPatterns\Behavioral\Specification;
/** /**
* A logical AND specification * A logical AND specification

View File

@@ -1,5 +1,5 @@
<?php <?php
namespace DesignPatterns\Specification; namespace DesignPatterns\Behavioral\Specification;
/** /**
* A specification to check an Item is priced between min and max * A specification to check an Item is priced between min and max

View File

@@ -1,5 +1,5 @@
<?php <?php
namespace DesignPatterns\Specification; namespace DesignPatterns\Behavioral\Specification;
/** /**
* An interface for a specification * An interface for a specification

View File

@@ -1,9 +1,9 @@
<?php <?php
namespace DesignPatterns\Tests\Specification; namespace DesignPatterns\Behavioral\Specification;
use DesignPatterns\Specification\PriceSpecification; use DesignPatterns\Behavioral\Specification\PriceSpecification;
use DesignPatterns\Specification\Item; use DesignPatterns\Behavioral\Specification\Item;
/** /**
* SpecificationTest tests the specification pattern * SpecificationTest tests the specification pattern

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace DesignPatterns\Status; namespace DesignPatterns\Behavioral\State;
/** /**
* Class CreateOrder * Class CreateOrder

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace DesignPatterns\Status; namespace DesignPatterns\Behavioral\State;
/** /**
* Class OrderController * Class OrderController

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace DesignPatterns\Status; namespace DesignPatterns\Behavioral\State;
/** /**
* Class OrderFactory * Class OrderFactory
@@ -9,7 +9,7 @@ class OrderFactory
{ {
private function __construct() private function __construct()
{ {
throw Exception('Can not instance the OrderFactory class!'); throw new \Exception('Can not instance the OrderFactory class!');
} }
/** /**

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace DesignPatterns\Status; namespace DesignPatterns\Behavioral\State;
/** /**
* Class OrderInterface * Class OrderInterface

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace DesignPatterns\Status; namespace DesignPatterns\Behavioral\State;
/** /**
* Class ShippingOrder * Class ShippingOrder

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace DesignPatterns\Strategy; namespace DesignPatterns\Behavioral\Strategy;
/** /**
* Class ComparatorInterface * Class ComparatorInterface

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace DesignPatterns\Strategy; namespace DesignPatterns\Behavioral\Strategy;
/** /**
* Class DateComparator * Class DateComparator

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace DesignPatterns\Strategy; namespace DesignPatterns\Behavioral\Strategy;
/** /**
* Class IdComparator * Class IdComparator

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace DesignPatterns\Strategy; namespace DesignPatterns\Behavioral\Strategy;
/** /**
* Class ObjectCollection * Class ObjectCollection

View File

@@ -1,11 +1,11 @@
<?php <?php
namespace DesignPatterns\Tests\Strategy; namespace DesignPatterns\Behavioral\Strategy;
use DesignPatterns\Strategy\DateComparator; use DesignPatterns\Behavioral\Strategy\DateComparator;
use DesignPatterns\Strategy\IdComparator; use DesignPatterns\Behavioral\Strategy\IdComparator;
use DesignPatterns\Strategy\ObjectCollection; use DesignPatterns\Behavioral\Strategy\ObjectCollection;
use DesignPatterns\Strategy\Strategy; use DesignPatterns\Behavioral\Strategy\Strategy;
/** /**
* Tests for Static Factory pattern * Tests for Static Factory pattern

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace DesignPatterns\TemplateMethod; namespace DesignPatterns\Behavioral\TemplateMethod;
/** /**
* BeachJourney is vacation at the beach * BeachJourney is vacation at the beach

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace DesignPatterns\TemplateMethod; namespace DesignPatterns\Behavioral\TemplateMethod;
/** /**
* CityJourney is a journey in a city * CityJourney is a journey in a city

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace DesignPatterns\TemplateMethod; namespace DesignPatterns\Behavioral\TemplateMethod;
/** /**
* *

View File

@@ -1,8 +1,8 @@
<?php <?php
namespace DesignPatterns\Tests\TemplateMethod; namespace DesignPatterns\Behavioral\TemplateMethod;
use DesignPatterns\TemplateMethod; use DesignPatterns\Behavioral\TemplateMethod;
/** /**
* JourneyTest tests all journeys * JourneyTest tests all journeys
@@ -29,7 +29,7 @@ class JourneyTest extends \PHPUnit_Framework_TestCase
*/ */
public function testLasVegas() public function testLasVegas()
{ {
$journey = $this->getMockForAbstractClass('DesignPatterns\TemplateMethod\Journey'); $journey = $this->getMockForAbstractClass('DesignPatterns\Behavioral\TemplateMethod\Journey');
$journey->expects($this->once()) $journey->expects($this->once())
->method('enjoyVacation') ->method('enjoyVacation')
->will($this->returnCallback(array($this, 'mockUpVacation'))); ->will($this->returnCallback(array($this, 'mockUpVacation')));

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace DesignPatterns\Visitor; namespace DesignPatterns\Behavioral\Visitor;
/** /**
* An example of a Visitor: Group * An example of a Visitor: Group

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace DesignPatterns\Visitor; namespace DesignPatterns\Behavioral\Visitor;
/** /**
* class Role * class Role
@@ -12,7 +12,7 @@ abstract class Role
* *
* Feel free to override it if your object must call another visiting behavior * Feel free to override it if your object must call another visiting behavior
* *
* @param \DesignPatterns\Visitor\RoleVisitorInterface $visitor * @param \DesignPatterns\Behavioral\Visitor\RoleVisitorInterface $visitor
* *
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
*/ */

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace DesignPatterns\Visitor; namespace DesignPatterns\Behavioral\Visitor;
/** /**
* Visitor Pattern * Visitor Pattern

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace DesignPatterns\Visitor; namespace DesignPatterns\Behavioral\Visitor;
/** /**
* Visitor Pattern * Visitor Pattern
@@ -18,14 +18,14 @@ interface RoleVisitorInterface
/** /**
* Visit a User object * Visit a User object
* *
* @param \DesignPatterns\Visitor\User $role * @param \DesignPatterns\Behavioral\Visitor\User $role
*/ */
public function visitUser(User $role); public function visitUser(User $role);
/** /**
* Visit a Group object * Visit a Group object
* *
* @param \DesignPatterns\Visitor\Group $role * @param \DesignPatterns\Behavioral\Visitor\Group $role
*/ */
public function visitGroup(Group $role); public function visitGroup(Group $role);
} }

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace DesignPatterns\Visitor; namespace DesignPatterns\Behavioral\Visitor;
/** /**
* Visitor Pattern * Visitor Pattern

View File

@@ -2,7 +2,7 @@
namespace DesignPatterns\Tests\Visitor; namespace DesignPatterns\Tests\Visitor;
use DesignPatterns\Visitor; use DesignPatterns\Behavioral\Visitor;
/** /**
* VisitorTest tests the visitor pattern * VisitorTest tests the visitor pattern
@@ -40,7 +40,7 @@ class VisitorTest extends \PHPUnit_Framework_TestCase
*/ */
public function testUnknownObject() public function testUnknownObject()
{ {
$mock = $this->getMockForAbstractClass('DesignPatterns\Visitor\Role'); $mock = $this->getMockForAbstractClass('DesignPatterns\Behavioral\Visitor\Role');
$mock->accept($this->visitor); $mock->accept($this->visitor);
} }

View File

@@ -3,7 +3,10 @@
<testsuites> <testsuites>
<testsuite name="Design Patterns"> <testsuite name="Design Patterns">
<directory>./Tests</directory> <directory>./Behavioral/*/*Test.php</directory>
<directory>./Creational/*/*/Test.php</directory>
<directory>./More/*/*/Test.php</directory>
<directory>./Structural/*/*/Test.php</directory>
</testsuite> </testsuite>
</testsuites> </testsuites>