From e59d70a0ac9319268b8aa217a5dce198c5abe061 Mon Sep 17 00:00:00 2001 From: Antonio Spinelli Date: Fri, 21 Mar 2014 18:03:44 -0300 Subject: [PATCH 01/17] start a restructure --- .../ChainOfResponsibilities}/Handler.php | 2 +- .../ChainOfResponsibilities}/README.md | 0 .../ChainOfResponsibilities}/Request.php | 2 +- .../Responsible/FastStorage.php | 6 +++--- .../Responsible/SlowStorage.php | 6 +++--- .../Tests}/ChainTest.php | 21 ++++++++++++------- .../Command}/CommandInterface.php | 0 .../Command}/HelloCommand.php | 0 {Command => Behavioral/Command}/Invoker.php | 0 {Command => Behavioral/Command}/README.md | 0 {Command => Behavioral/Command}/Receiver.php | 0 .../Command/Test}/CommandTest.php | 0 {Iterator => Behavioral/Iterator}/File.php | 0 {Iterator => Behavioral/Iterator}/README.md | 0 {Iterator => Behavioral/Iterator}/Row.php | 0 {Iterator => Behavioral/Iterator}/RowSet.php | 0 .../Mediator}/Colleague.php | 0 .../Mediator}/Mediator.php | 0 .../Mediator}/MediatorInterface.php | 0 {Mediator => Behavioral/Mediator}/README.md | 0 .../Mediator}/Subsystem/Client.php | 0 .../Mediator}/Subsystem/Database.php | 0 .../Mediator}/Subsystem/Server.php | 0 .../Mediator/Test}/MediatorTest.php | 0 .../NullObject}/LoggerInterface.php | 0 .../NullObject}/NullLogger.php | 0 .../NullObject}/PrintLogger.php | 0 .../NullObject}/README.md | 0 .../NullObject}/Service.php | 0 .../NullObject/Test}/LoggerTest.php | 0 {Observer => Behavioral/Observer}/README.md | 0 .../Observer/Test}/ObserverTest.php | 0 {Observer => Behavioral/Observer}/User.php | 0 .../Observer}/UserObserver.php | 0 .../Specification}/AbstractSpecification.php | 0 .../Specification}/Either.php | 0 .../Specification}/Item.php | 0 .../Specification}/Not.php | 0 .../Specification}/Plus.php | 0 .../Specification}/PriceSpecification.php | 0 .../Specification}/README.md | 0 .../Specification}/SpecificationInterface.php | 0 .../Specification/Test}/SpecificationTest.php | 0 {State => Behavioral/State}/CreateOrder.php | 0 .../State}/OrderController.php | 0 {State => Behavioral/State}/OrderFactory.php | 0 .../State}/OrderInterface.php | 0 {State => Behavioral/State}/README.md | 0 {State => Behavioral/State}/ShippingOrder.php | 0 .../Strategy}/ComparatorInterface.php | 0 .../Strategy}/DateComparator.php | 0 .../Strategy}/IdComparator.php | 0 .../Strategy}/ObjectCollection.php | 0 {Strategy => Behavioral/Strategy}/README.md | 0 {Strategy => Behavioral/Strategy}/index.php | 0 .../TemplateMethod}/BeachJourney.php | 0 .../TemplateMethod}/CityJourney.php | 0 .../TemplateMethod}/Journey.php | 0 .../TemplateMethod}/README.md | 0 .../TemplateMethod/Test}/JourneyTest.php | 0 {Visitor => Behavioral/Visitor}/Group.php | 0 {Visitor => Behavioral/Visitor}/README.md | 0 {Visitor => Behavioral/Visitor}/Role.php | 0 .../Visitor}/RolePrintVisitor.php | 0 .../Visitor}/RoleVisitorInterface.php | 0 .../Visitor/Test}/VisitorTest.php | 0 {Visitor => Behavioral/Visitor}/User.php | 0 .../AbstractFactory}/AbstractFactory.php | 0 .../AbstractFactory}/Html/Picture.php | 0 .../AbstractFactory}/Html/Text.php | 0 .../AbstractFactory}/HtmlFactory.php | 0 .../AbstractFactory}/Json/Picture.php | 0 .../AbstractFactory}/Json/Text.php | 0 .../AbstractFactory}/JsonFactory.php | 0 .../AbstractFactory}/MediaInterface.php | 0 .../AbstractFactory}/Picture.php | 0 .../AbstractFactory}/README.md | 0 .../Test}/AbstractFactoryTest.php | 0 .../AbstractFactory}/Text.php | 0 .../Builder}/BikeBuilder.php | 0 .../Builder}/BuilderInterface.php | 0 .../Builder}/CarBuilder.php | 0 {Builder => Creational/Builder}/Director.php | 0 .../Builder}/Parts/Bike.php | 0 {Builder => Creational/Builder}/Parts/Car.php | 0 .../Builder}/Parts/Door.php | 0 .../Builder}/Parts/Engine.php | 0 .../Builder}/Parts/README.md | 0 .../Builder}/Parts/Vehicle.php | 0 .../Builder}/Parts/Wheel.php | 0 {Builder => Creational/Builder}/README.md | 0 .../Builder/Test}/DirectorTest.php | 0 .../FactoryMethod}/Bicycle.php | 0 .../FactoryMethod}/FactoryMethod.php | 0 .../FactoryMethod}/Ferrari.php | 0 .../FactoryMethod}/GermanFactory.php | 0 .../FactoryMethod}/ItalianFactory.php | 0 .../FactoryMethod}/Porsche.php | 0 .../FactoryMethod}/README.md | 0 .../FactoryMethod/Test}/FactoryMethodTest.php | 0 .../FactoryMethod}/VehicleInterface.php | 0 .../Multiton}/Multiton.php | 0 {Multiton => Creational/Multiton}/README.md | 0 .../Prototype}/BarBookPrototype.php | 0 .../Prototype}/BookPrototype.php | 0 .../Prototype}/FooBookPrototype.php | 0 {Prototype => Creational/Prototype}/README.md | 0 {Prototype => Creational/Prototype}/index.php | 0 .../SimpleFactory}/Bicycle.php | 0 .../SimpleFactory}/ConcreteFactory.php | 0 .../SimpleFactory}/README.md | 0 .../SimpleFactory}/Scooter.php | 0 .../SimpleFactory/Test}/SimpleFactoryTest.php | 0 .../SimpleFactory}/VehicleInterface.php | 0 {Singleton => Creational/Singleton}/README.md | 0 .../Singleton}/Singleton.php | 0 .../Singleton/Test}/SingletonTest.php | 0 .../StaticFactory}/FormatNumber.php | 0 .../StaticFactory}/FormatString.php | 0 .../StaticFactory}/FormatterInterface.php | 0 .../StaticFactory}/README.md | 0 .../StaticFactory}/StaticFactory.php | 0 .../StaticFactory/Test}/StaticFactoryTest.php | 0 .../Delegation}/JuniorDeveloper.php | 0 {Delegation => More/Delegation}/TeamLead.php | 0 .../Delegation/Test}/DelegationTest.php | 0 {Delegation => More/Delegation}/Usage.php | 0 .../ServiceLocator}/DatabaseService.php | 0 .../DatabaseServiceInterface.php | 0 .../ServiceLocator}/LogService.php | 0 .../ServiceLocator}/LogServiceInterface.php | 0 .../ServiceLocator}/README.md | 0 .../ServiceLocator}/ServiceLocator.php | 0 .../ServiceLocatorInterface.php | 0 .../Test}/ServiceLocatorTest.php | 0 {Adapter => Structural/Adapter}/Book.php | 0 .../Adapter}/EBookAdapter.php | 0 .../Adapter}/EBookInterface.php | 0 {Adapter => Structural/Adapter}/Kindle.php | 0 .../Adapter}/PaperBookInterface.php | 0 {Adapter => Structural/Adapter}/README.md | 0 .../Adapter/Test}/AdapterTest.php | 0 {Composite => Structural/Composite}/Form.php | 0 .../Composite}/FormElement.php | 0 .../Composite}/InputElement.php | 0 {Composite => Structural/Composite}/README.md | 0 .../Composite/Test}/FormTest.php | 0 .../Composite}/TextElement.php | 0 .../DataMapper}/README.md | 0 .../DataMapper/Test}/UserMapperTest.php | 0 .../DataMapper}/User.php | 0 .../DataMapper}/UserMapper.php | 0 .../Decorator}/Decorator.php | 0 {Decorator => Structural/Decorator}/README.md | 0 .../Decorator}/RenderInJson.php | 0 .../Decorator}/RenderInXml.php | 0 .../Decorator}/RendererInterface.php | 0 .../Decorator/Test}/DecoratorTest.php | 0 .../Decorator}/Webservice.php | 0 .../DependencyInjection}/AbstractConfig.php | 0 .../DependencyInjection}/ArrayConfig.php | 0 .../DependencyInjection}/Connection.php | 0 .../DependencyInjection}/Parameters.php | 0 .../DependencyInjection}/README.md | 0 .../Test}/DependencyInjectionTest.php | 0 .../DependencyInjection/Test}/config.php | 0 .../Facade}/BiosInterface.php | 0 {Facade => Structural/Facade}/Facade.php | 0 {Facade => Structural/Facade}/OsInterface.php | 0 {Facade => Structural/Facade}/README.md | 0 .../Facade/Test}/FacadeTest.php | 0 .../FluentInterface}/README.md | 0 .../FluentInterface}/SQL.php | 0 .../Test}/FluentInterfaceTest.php | 0 {Proxy => Structural/Proxy}/README.md | 0 {Proxy => Structural/Proxy}/Record.php | 0 {Proxy => Structural/Proxy}/RecordProxy.php | 0 {Registry => Structural/Registry}/README.md | 0 .../Registry}/Registry.php | 0 {Registry => Structural/Registry}/index.php | 0 180 files changed, 21 insertions(+), 16 deletions(-) rename {ChainOfResponsibilities => Behavioral/ChainOfResponsibilities}/Handler.php (97%) rename {ChainOfResponsibilities => Behavioral/ChainOfResponsibilities}/README.md (100%) rename {ChainOfResponsibilities => Behavioral/ChainOfResponsibilities}/Request.php (91%) rename {ChainOfResponsibilities => Behavioral/ChainOfResponsibilities}/Responsible/FastStorage.php (79%) rename {ChainOfResponsibilities => Behavioral/ChainOfResponsibilities}/Responsible/SlowStorage.php (83%) rename {Tests/ChainOfResponsibilities => Behavioral/ChainOfResponsibilities/Tests}/ChainTest.php (60%) rename {Command => Behavioral/Command}/CommandInterface.php (100%) rename {Command => Behavioral/Command}/HelloCommand.php (100%) rename {Command => Behavioral/Command}/Invoker.php (100%) rename {Command => Behavioral/Command}/README.md (100%) rename {Command => Behavioral/Command}/Receiver.php (100%) rename {Tests/Command => Behavioral/Command/Test}/CommandTest.php (100%) rename {Iterator => Behavioral/Iterator}/File.php (100%) rename {Iterator => Behavioral/Iterator}/README.md (100%) rename {Iterator => Behavioral/Iterator}/Row.php (100%) rename {Iterator => Behavioral/Iterator}/RowSet.php (100%) rename {Mediator => Behavioral/Mediator}/Colleague.php (100%) rename {Mediator => Behavioral/Mediator}/Mediator.php (100%) rename {Mediator => Behavioral/Mediator}/MediatorInterface.php (100%) rename {Mediator => Behavioral/Mediator}/README.md (100%) rename {Mediator => Behavioral/Mediator}/Subsystem/Client.php (100%) rename {Mediator => Behavioral/Mediator}/Subsystem/Database.php (100%) rename {Mediator => Behavioral/Mediator}/Subsystem/Server.php (100%) rename {Tests/Mediator => Behavioral/Mediator/Test}/MediatorTest.php (100%) rename {NullObject => Behavioral/NullObject}/LoggerInterface.php (100%) rename {NullObject => Behavioral/NullObject}/NullLogger.php (100%) rename {NullObject => Behavioral/NullObject}/PrintLogger.php (100%) rename {NullObject => Behavioral/NullObject}/README.md (100%) rename {NullObject => Behavioral/NullObject}/Service.php (100%) rename {Tests/NullObject => Behavioral/NullObject/Test}/LoggerTest.php (100%) rename {Observer => Behavioral/Observer}/README.md (100%) rename {Tests/Observer => Behavioral/Observer/Test}/ObserverTest.php (100%) rename {Observer => Behavioral/Observer}/User.php (100%) rename {Observer => Behavioral/Observer}/UserObserver.php (100%) rename {Specification => Behavioral/Specification}/AbstractSpecification.php (100%) mode change 100755 => 100644 rename {Specification => Behavioral/Specification}/Either.php (100%) mode change 100755 => 100644 rename {Specification => Behavioral/Specification}/Item.php (100%) rename {Specification => Behavioral/Specification}/Not.php (100%) mode change 100755 => 100644 rename {Specification => Behavioral/Specification}/Plus.php (100%) mode change 100755 => 100644 rename {Specification => Behavioral/Specification}/PriceSpecification.php (100%) rename {Specification => Behavioral/Specification}/README.md (100%) rename {Specification => Behavioral/Specification}/SpecificationInterface.php (100%) mode change 100755 => 100644 rename {Tests/Specification => Behavioral/Specification/Test}/SpecificationTest.php (100%) rename {State => Behavioral/State}/CreateOrder.php (100%) rename {State => Behavioral/State}/OrderController.php (100%) rename {State => Behavioral/State}/OrderFactory.php (100%) rename {State => Behavioral/State}/OrderInterface.php (100%) rename {State => Behavioral/State}/README.md (100%) rename {State => Behavioral/State}/ShippingOrder.php (100%) rename {Strategy => Behavioral/Strategy}/ComparatorInterface.php (100%) rename {Strategy => Behavioral/Strategy}/DateComparator.php (100%) rename {Strategy => Behavioral/Strategy}/IdComparator.php (100%) rename {Strategy => Behavioral/Strategy}/ObjectCollection.php (100%) rename {Strategy => Behavioral/Strategy}/README.md (100%) rename {Strategy => Behavioral/Strategy}/index.php (100%) rename {TemplateMethod => Behavioral/TemplateMethod}/BeachJourney.php (100%) rename {TemplateMethod => Behavioral/TemplateMethod}/CityJourney.php (100%) rename {TemplateMethod => Behavioral/TemplateMethod}/Journey.php (100%) rename {TemplateMethod => Behavioral/TemplateMethod}/README.md (100%) rename {Tests/TemplateMethod => Behavioral/TemplateMethod/Test}/JourneyTest.php (100%) rename {Visitor => Behavioral/Visitor}/Group.php (100%) rename {Visitor => Behavioral/Visitor}/README.md (100%) rename {Visitor => Behavioral/Visitor}/Role.php (100%) rename {Visitor => Behavioral/Visitor}/RolePrintVisitor.php (100%) rename {Visitor => Behavioral/Visitor}/RoleVisitorInterface.php (100%) rename {Tests/Visitor => Behavioral/Visitor/Test}/VisitorTest.php (100%) rename {Visitor => Behavioral/Visitor}/User.php (100%) rename {AbstractFactory => Creational/AbstractFactory}/AbstractFactory.php (100%) rename {AbstractFactory => Creational/AbstractFactory}/Html/Picture.php (100%) rename {AbstractFactory => Creational/AbstractFactory}/Html/Text.php (100%) rename {AbstractFactory => Creational/AbstractFactory}/HtmlFactory.php (100%) rename {AbstractFactory => Creational/AbstractFactory}/Json/Picture.php (100%) rename {AbstractFactory => Creational/AbstractFactory}/Json/Text.php (100%) rename {AbstractFactory => Creational/AbstractFactory}/JsonFactory.php (100%) rename {AbstractFactory => Creational/AbstractFactory}/MediaInterface.php (100%) rename {AbstractFactory => Creational/AbstractFactory}/Picture.php (100%) rename {AbstractFactory => Creational/AbstractFactory}/README.md (100%) rename {Tests/AbstractFactory => Creational/AbstractFactory/Test}/AbstractFactoryTest.php (100%) rename {AbstractFactory => Creational/AbstractFactory}/Text.php (100%) rename {Builder => Creational/Builder}/BikeBuilder.php (100%) rename {Builder => Creational/Builder}/BuilderInterface.php (100%) rename {Builder => Creational/Builder}/CarBuilder.php (100%) rename {Builder => Creational/Builder}/Director.php (100%) rename {Builder => Creational/Builder}/Parts/Bike.php (100%) rename {Builder => Creational/Builder}/Parts/Car.php (100%) rename {Builder => Creational/Builder}/Parts/Door.php (100%) rename {Builder => Creational/Builder}/Parts/Engine.php (100%) rename {Builder => Creational/Builder}/Parts/README.md (100%) rename {Builder => Creational/Builder}/Parts/Vehicle.php (100%) rename {Builder => Creational/Builder}/Parts/Wheel.php (100%) rename {Builder => Creational/Builder}/README.md (100%) rename {Tests/Builder => Creational/Builder/Test}/DirectorTest.php (100%) rename {FactoryMethod => Creational/FactoryMethod}/Bicycle.php (100%) rename {FactoryMethod => Creational/FactoryMethod}/FactoryMethod.php (100%) rename {FactoryMethod => Creational/FactoryMethod}/Ferrari.php (100%) rename {FactoryMethod => Creational/FactoryMethod}/GermanFactory.php (100%) rename {FactoryMethod => Creational/FactoryMethod}/ItalianFactory.php (100%) rename {FactoryMethod => Creational/FactoryMethod}/Porsche.php (100%) rename {FactoryMethod => Creational/FactoryMethod}/README.md (100%) rename {Tests/FactoryMethod => Creational/FactoryMethod/Test}/FactoryMethodTest.php (100%) rename {FactoryMethod => Creational/FactoryMethod}/VehicleInterface.php (100%) rename {Multiton => Creational/Multiton}/Multiton.php (100%) rename {Multiton => Creational/Multiton}/README.md (100%) rename {Prototype => Creational/Prototype}/BarBookPrototype.php (100%) rename {Prototype => Creational/Prototype}/BookPrototype.php (100%) rename {Prototype => Creational/Prototype}/FooBookPrototype.php (100%) rename {Prototype => Creational/Prototype}/README.md (100%) rename {Prototype => Creational/Prototype}/index.php (100%) rename {SimpleFactory => Creational/SimpleFactory}/Bicycle.php (100%) rename {SimpleFactory => Creational/SimpleFactory}/ConcreteFactory.php (100%) rename {SimpleFactory => Creational/SimpleFactory}/README.md (100%) rename {SimpleFactory => Creational/SimpleFactory}/Scooter.php (100%) rename {Tests/SimpleFactory => Creational/SimpleFactory/Test}/SimpleFactoryTest.php (100%) rename {SimpleFactory => Creational/SimpleFactory}/VehicleInterface.php (100%) rename {Singleton => Creational/Singleton}/README.md (100%) rename {Singleton => Creational/Singleton}/Singleton.php (100%) rename {Tests/Singleton => Creational/Singleton/Test}/SingletonTest.php (100%) rename {StaticFactory => Creational/StaticFactory}/FormatNumber.php (100%) rename {StaticFactory => Creational/StaticFactory}/FormatString.php (100%) rename {StaticFactory => Creational/StaticFactory}/FormatterInterface.php (100%) rename {StaticFactory => Creational/StaticFactory}/README.md (100%) rename {StaticFactory => Creational/StaticFactory}/StaticFactory.php (100%) rename {Tests/StaticFactory => Creational/StaticFactory/Test}/StaticFactoryTest.php (100%) rename {Delegation => More/Delegation}/JuniorDeveloper.php (100%) rename {Delegation => More/Delegation}/TeamLead.php (100%) rename {Tests/Delegation => More/Delegation/Test}/DelegationTest.php (100%) rename {Delegation => More/Delegation}/Usage.php (100%) rename {ServiceLocator => More/ServiceLocator}/DatabaseService.php (100%) rename {ServiceLocator => More/ServiceLocator}/DatabaseServiceInterface.php (100%) rename {ServiceLocator => More/ServiceLocator}/LogService.php (100%) rename {ServiceLocator => More/ServiceLocator}/LogServiceInterface.php (100%) rename {ServiceLocator => More/ServiceLocator}/README.md (100%) rename {ServiceLocator => More/ServiceLocator}/ServiceLocator.php (100%) rename {ServiceLocator => More/ServiceLocator}/ServiceLocatorInterface.php (100%) rename {Tests/ServiceLocator => More/ServiceLocator/Test}/ServiceLocatorTest.php (100%) rename {Adapter => Structural/Adapter}/Book.php (100%) rename {Adapter => Structural/Adapter}/EBookAdapter.php (100%) rename {Adapter => Structural/Adapter}/EBookInterface.php (100%) rename {Adapter => Structural/Adapter}/Kindle.php (100%) rename {Adapter => Structural/Adapter}/PaperBookInterface.php (100%) rename {Adapter => Structural/Adapter}/README.md (100%) rename {Tests/Adapter => Structural/Adapter/Test}/AdapterTest.php (100%) rename {Composite => Structural/Composite}/Form.php (100%) rename {Composite => Structural/Composite}/FormElement.php (100%) rename {Composite => Structural/Composite}/InputElement.php (100%) rename {Composite => Structural/Composite}/README.md (100%) rename {Tests/Composite => Structural/Composite/Test}/FormTest.php (100%) rename {Composite => Structural/Composite}/TextElement.php (100%) rename {DataMapper => Structural/DataMapper}/README.md (100%) rename {Tests/DataMapper => Structural/DataMapper/Test}/UserMapperTest.php (100%) rename {DataMapper => Structural/DataMapper}/User.php (100%) rename {DataMapper => Structural/DataMapper}/UserMapper.php (100%) rename {Decorator => Structural/Decorator}/Decorator.php (100%) rename {Decorator => Structural/Decorator}/README.md (100%) rename {Decorator => Structural/Decorator}/RenderInJson.php (100%) rename {Decorator => Structural/Decorator}/RenderInXml.php (100%) rename {Decorator => Structural/Decorator}/RendererInterface.php (100%) rename {Tests/Decorator => Structural/Decorator/Test}/DecoratorTest.php (100%) rename {Decorator => Structural/Decorator}/Webservice.php (100%) rename {DependencyInjection => Structural/DependencyInjection}/AbstractConfig.php (100%) rename {DependencyInjection => Structural/DependencyInjection}/ArrayConfig.php (100%) rename {DependencyInjection => Structural/DependencyInjection}/Connection.php (100%) rename {DependencyInjection => Structural/DependencyInjection}/Parameters.php (100%) rename {DependencyInjection => Structural/DependencyInjection}/README.md (100%) rename {Tests/DependencyInjection => Structural/DependencyInjection/Test}/DependencyInjectionTest.php (100%) rename {Tests/DependencyInjection => Structural/DependencyInjection/Test}/config.php (100%) rename {Facade => Structural/Facade}/BiosInterface.php (100%) rename {Facade => Structural/Facade}/Facade.php (100%) rename {Facade => Structural/Facade}/OsInterface.php (100%) rename {Facade => Structural/Facade}/README.md (100%) rename {Tests/Facade => Structural/Facade/Test}/FacadeTest.php (100%) rename {FluentInterface => Structural/FluentInterface}/README.md (100%) rename {FluentInterface => Structural/FluentInterface}/SQL.php (100%) rename {Tests/FluentInterface => Structural/FluentInterface/Test}/FluentInterfaceTest.php (100%) rename {Proxy => Structural/Proxy}/README.md (100%) rename {Proxy => Structural/Proxy}/Record.php (100%) rename {Proxy => Structural/Proxy}/RecordProxy.php (100%) rename {Registry => Structural/Registry}/README.md (100%) rename {Registry => Structural/Registry}/Registry.php (100%) rename {Registry => Structural/Registry}/index.php (100%) diff --git a/ChainOfResponsibilities/Handler.php b/Behavioral/ChainOfResponsibilities/Handler.php similarity index 97% rename from ChainOfResponsibilities/Handler.php rename to Behavioral/ChainOfResponsibilities/Handler.php index 35ec769..74a89f8 100644 --- a/ChainOfResponsibilities/Handler.php +++ b/Behavioral/ChainOfResponsibilities/Handler.php @@ -1,6 +1,6 @@ chain = new Responsible\FastStorage(array('bar' => 'baz')); - $this->chain->append(new Responsible\SlowStorage(array('bar' => 'baz', 'foo' => 'bar'))); + $this->chain = new FastStorage(array('bar' => 'baz')); + $this->chain->append(new SlowStorage(array('bar' => 'baz', 'foo' => 'bar'))); } public function makeRequest() @@ -40,7 +45,7 @@ class ChainTest extends \PHPUnit_Framework_TestCase $this->assertObjectHasAttribute('response', $request); $this->assertEquals('baz', $request->response); // despite both handle owns the 'bar' key, the FastStorage is responding first - $this->assertEquals('DesignPatterns\ChainOfResponsibilities\Responsible\FastStorage', $request->forDebugOnly); + $this->assertEquals('DesignPatterns\Behavioral\ChainOfResponsibilities\Responsible\FastStorage', $request->forDebugOnly); } /** @@ -55,7 +60,7 @@ class ChainTest extends \PHPUnit_Framework_TestCase $this->assertObjectHasAttribute('response', $request); $this->assertEquals('bar', $request->response); // FastStorage has no 'foo' key, the SlowStorage is responding - $this->assertEquals('DesignPatterns\ChainOfResponsibilities\Responsible\SlowStorage', $request->forDebugOnly); + $this->assertEquals('DesignPatterns\Behavioral\ChainOfResponsibilities\Responsible\SlowStorage', $request->forDebugOnly); } /** @@ -68,6 +73,6 @@ class ChainTest extends \PHPUnit_Framework_TestCase $this->assertFalse($ret); // the last responsible : - $this->assertEquals('DesignPatterns\ChainOfResponsibilities\Responsible\SlowStorage', $request->forDebugOnly); + $this->assertEquals('DesignPatterns\Behavioral\ChainOfResponsibilities\Responsible\SlowStorage', $request->forDebugOnly); } } diff --git a/Command/CommandInterface.php b/Behavioral/Command/CommandInterface.php similarity index 100% rename from Command/CommandInterface.php rename to Behavioral/Command/CommandInterface.php diff --git a/Command/HelloCommand.php b/Behavioral/Command/HelloCommand.php similarity index 100% rename from Command/HelloCommand.php rename to Behavioral/Command/HelloCommand.php diff --git a/Command/Invoker.php b/Behavioral/Command/Invoker.php similarity index 100% rename from Command/Invoker.php rename to Behavioral/Command/Invoker.php diff --git a/Command/README.md b/Behavioral/Command/README.md similarity index 100% rename from Command/README.md rename to Behavioral/Command/README.md diff --git a/Command/Receiver.php b/Behavioral/Command/Receiver.php similarity index 100% rename from Command/Receiver.php rename to Behavioral/Command/Receiver.php diff --git a/Tests/Command/CommandTest.php b/Behavioral/Command/Test/CommandTest.php similarity index 100% rename from Tests/Command/CommandTest.php rename to Behavioral/Command/Test/CommandTest.php diff --git a/Iterator/File.php b/Behavioral/Iterator/File.php similarity index 100% rename from Iterator/File.php rename to Behavioral/Iterator/File.php diff --git a/Iterator/README.md b/Behavioral/Iterator/README.md similarity index 100% rename from Iterator/README.md rename to Behavioral/Iterator/README.md diff --git a/Iterator/Row.php b/Behavioral/Iterator/Row.php similarity index 100% rename from Iterator/Row.php rename to Behavioral/Iterator/Row.php diff --git a/Iterator/RowSet.php b/Behavioral/Iterator/RowSet.php similarity index 100% rename from Iterator/RowSet.php rename to Behavioral/Iterator/RowSet.php diff --git a/Mediator/Colleague.php b/Behavioral/Mediator/Colleague.php similarity index 100% rename from Mediator/Colleague.php rename to Behavioral/Mediator/Colleague.php diff --git a/Mediator/Mediator.php b/Behavioral/Mediator/Mediator.php similarity index 100% rename from Mediator/Mediator.php rename to Behavioral/Mediator/Mediator.php diff --git a/Mediator/MediatorInterface.php b/Behavioral/Mediator/MediatorInterface.php similarity index 100% rename from Mediator/MediatorInterface.php rename to Behavioral/Mediator/MediatorInterface.php diff --git a/Mediator/README.md b/Behavioral/Mediator/README.md similarity index 100% rename from Mediator/README.md rename to Behavioral/Mediator/README.md diff --git a/Mediator/Subsystem/Client.php b/Behavioral/Mediator/Subsystem/Client.php similarity index 100% rename from Mediator/Subsystem/Client.php rename to Behavioral/Mediator/Subsystem/Client.php diff --git a/Mediator/Subsystem/Database.php b/Behavioral/Mediator/Subsystem/Database.php similarity index 100% rename from Mediator/Subsystem/Database.php rename to Behavioral/Mediator/Subsystem/Database.php diff --git a/Mediator/Subsystem/Server.php b/Behavioral/Mediator/Subsystem/Server.php similarity index 100% rename from Mediator/Subsystem/Server.php rename to Behavioral/Mediator/Subsystem/Server.php diff --git a/Tests/Mediator/MediatorTest.php b/Behavioral/Mediator/Test/MediatorTest.php similarity index 100% rename from Tests/Mediator/MediatorTest.php rename to Behavioral/Mediator/Test/MediatorTest.php diff --git a/NullObject/LoggerInterface.php b/Behavioral/NullObject/LoggerInterface.php similarity index 100% rename from NullObject/LoggerInterface.php rename to Behavioral/NullObject/LoggerInterface.php diff --git a/NullObject/NullLogger.php b/Behavioral/NullObject/NullLogger.php similarity index 100% rename from NullObject/NullLogger.php rename to Behavioral/NullObject/NullLogger.php diff --git a/NullObject/PrintLogger.php b/Behavioral/NullObject/PrintLogger.php similarity index 100% rename from NullObject/PrintLogger.php rename to Behavioral/NullObject/PrintLogger.php diff --git a/NullObject/README.md b/Behavioral/NullObject/README.md similarity index 100% rename from NullObject/README.md rename to Behavioral/NullObject/README.md diff --git a/NullObject/Service.php b/Behavioral/NullObject/Service.php similarity index 100% rename from NullObject/Service.php rename to Behavioral/NullObject/Service.php diff --git a/Tests/NullObject/LoggerTest.php b/Behavioral/NullObject/Test/LoggerTest.php similarity index 100% rename from Tests/NullObject/LoggerTest.php rename to Behavioral/NullObject/Test/LoggerTest.php diff --git a/Observer/README.md b/Behavioral/Observer/README.md similarity index 100% rename from Observer/README.md rename to Behavioral/Observer/README.md diff --git a/Tests/Observer/ObserverTest.php b/Behavioral/Observer/Test/ObserverTest.php similarity index 100% rename from Tests/Observer/ObserverTest.php rename to Behavioral/Observer/Test/ObserverTest.php diff --git a/Observer/User.php b/Behavioral/Observer/User.php similarity index 100% rename from Observer/User.php rename to Behavioral/Observer/User.php diff --git a/Observer/UserObserver.php b/Behavioral/Observer/UserObserver.php similarity index 100% rename from Observer/UserObserver.php rename to Behavioral/Observer/UserObserver.php diff --git a/Specification/AbstractSpecification.php b/Behavioral/Specification/AbstractSpecification.php old mode 100755 new mode 100644 similarity index 100% rename from Specification/AbstractSpecification.php rename to Behavioral/Specification/AbstractSpecification.php diff --git a/Specification/Either.php b/Behavioral/Specification/Either.php old mode 100755 new mode 100644 similarity index 100% rename from Specification/Either.php rename to Behavioral/Specification/Either.php diff --git a/Specification/Item.php b/Behavioral/Specification/Item.php similarity index 100% rename from Specification/Item.php rename to Behavioral/Specification/Item.php diff --git a/Specification/Not.php b/Behavioral/Specification/Not.php old mode 100755 new mode 100644 similarity index 100% rename from Specification/Not.php rename to Behavioral/Specification/Not.php diff --git a/Specification/Plus.php b/Behavioral/Specification/Plus.php old mode 100755 new mode 100644 similarity index 100% rename from Specification/Plus.php rename to Behavioral/Specification/Plus.php diff --git a/Specification/PriceSpecification.php b/Behavioral/Specification/PriceSpecification.php similarity index 100% rename from Specification/PriceSpecification.php rename to Behavioral/Specification/PriceSpecification.php diff --git a/Specification/README.md b/Behavioral/Specification/README.md similarity index 100% rename from Specification/README.md rename to Behavioral/Specification/README.md diff --git a/Specification/SpecificationInterface.php b/Behavioral/Specification/SpecificationInterface.php old mode 100755 new mode 100644 similarity index 100% rename from Specification/SpecificationInterface.php rename to Behavioral/Specification/SpecificationInterface.php diff --git a/Tests/Specification/SpecificationTest.php b/Behavioral/Specification/Test/SpecificationTest.php similarity index 100% rename from Tests/Specification/SpecificationTest.php rename to Behavioral/Specification/Test/SpecificationTest.php diff --git a/State/CreateOrder.php b/Behavioral/State/CreateOrder.php similarity index 100% rename from State/CreateOrder.php rename to Behavioral/State/CreateOrder.php diff --git a/State/OrderController.php b/Behavioral/State/OrderController.php similarity index 100% rename from State/OrderController.php rename to Behavioral/State/OrderController.php diff --git a/State/OrderFactory.php b/Behavioral/State/OrderFactory.php similarity index 100% rename from State/OrderFactory.php rename to Behavioral/State/OrderFactory.php diff --git a/State/OrderInterface.php b/Behavioral/State/OrderInterface.php similarity index 100% rename from State/OrderInterface.php rename to Behavioral/State/OrderInterface.php diff --git a/State/README.md b/Behavioral/State/README.md similarity index 100% rename from State/README.md rename to Behavioral/State/README.md diff --git a/State/ShippingOrder.php b/Behavioral/State/ShippingOrder.php similarity index 100% rename from State/ShippingOrder.php rename to Behavioral/State/ShippingOrder.php diff --git a/Strategy/ComparatorInterface.php b/Behavioral/Strategy/ComparatorInterface.php similarity index 100% rename from Strategy/ComparatorInterface.php rename to Behavioral/Strategy/ComparatorInterface.php diff --git a/Strategy/DateComparator.php b/Behavioral/Strategy/DateComparator.php similarity index 100% rename from Strategy/DateComparator.php rename to Behavioral/Strategy/DateComparator.php diff --git a/Strategy/IdComparator.php b/Behavioral/Strategy/IdComparator.php similarity index 100% rename from Strategy/IdComparator.php rename to Behavioral/Strategy/IdComparator.php diff --git a/Strategy/ObjectCollection.php b/Behavioral/Strategy/ObjectCollection.php similarity index 100% rename from Strategy/ObjectCollection.php rename to Behavioral/Strategy/ObjectCollection.php diff --git a/Strategy/README.md b/Behavioral/Strategy/README.md similarity index 100% rename from Strategy/README.md rename to Behavioral/Strategy/README.md diff --git a/Strategy/index.php b/Behavioral/Strategy/index.php similarity index 100% rename from Strategy/index.php rename to Behavioral/Strategy/index.php diff --git a/TemplateMethod/BeachJourney.php b/Behavioral/TemplateMethod/BeachJourney.php similarity index 100% rename from TemplateMethod/BeachJourney.php rename to Behavioral/TemplateMethod/BeachJourney.php diff --git a/TemplateMethod/CityJourney.php b/Behavioral/TemplateMethod/CityJourney.php similarity index 100% rename from TemplateMethod/CityJourney.php rename to Behavioral/TemplateMethod/CityJourney.php diff --git a/TemplateMethod/Journey.php b/Behavioral/TemplateMethod/Journey.php similarity index 100% rename from TemplateMethod/Journey.php rename to Behavioral/TemplateMethod/Journey.php diff --git a/TemplateMethod/README.md b/Behavioral/TemplateMethod/README.md similarity index 100% rename from TemplateMethod/README.md rename to Behavioral/TemplateMethod/README.md diff --git a/Tests/TemplateMethod/JourneyTest.php b/Behavioral/TemplateMethod/Test/JourneyTest.php similarity index 100% rename from Tests/TemplateMethod/JourneyTest.php rename to Behavioral/TemplateMethod/Test/JourneyTest.php diff --git a/Visitor/Group.php b/Behavioral/Visitor/Group.php similarity index 100% rename from Visitor/Group.php rename to Behavioral/Visitor/Group.php diff --git a/Visitor/README.md b/Behavioral/Visitor/README.md similarity index 100% rename from Visitor/README.md rename to Behavioral/Visitor/README.md diff --git a/Visitor/Role.php b/Behavioral/Visitor/Role.php similarity index 100% rename from Visitor/Role.php rename to Behavioral/Visitor/Role.php diff --git a/Visitor/RolePrintVisitor.php b/Behavioral/Visitor/RolePrintVisitor.php similarity index 100% rename from Visitor/RolePrintVisitor.php rename to Behavioral/Visitor/RolePrintVisitor.php diff --git a/Visitor/RoleVisitorInterface.php b/Behavioral/Visitor/RoleVisitorInterface.php similarity index 100% rename from Visitor/RoleVisitorInterface.php rename to Behavioral/Visitor/RoleVisitorInterface.php diff --git a/Tests/Visitor/VisitorTest.php b/Behavioral/Visitor/Test/VisitorTest.php similarity index 100% rename from Tests/Visitor/VisitorTest.php rename to Behavioral/Visitor/Test/VisitorTest.php diff --git a/Visitor/User.php b/Behavioral/Visitor/User.php similarity index 100% rename from Visitor/User.php rename to Behavioral/Visitor/User.php diff --git a/AbstractFactory/AbstractFactory.php b/Creational/AbstractFactory/AbstractFactory.php similarity index 100% rename from AbstractFactory/AbstractFactory.php rename to Creational/AbstractFactory/AbstractFactory.php diff --git a/AbstractFactory/Html/Picture.php b/Creational/AbstractFactory/Html/Picture.php similarity index 100% rename from AbstractFactory/Html/Picture.php rename to Creational/AbstractFactory/Html/Picture.php diff --git a/AbstractFactory/Html/Text.php b/Creational/AbstractFactory/Html/Text.php similarity index 100% rename from AbstractFactory/Html/Text.php rename to Creational/AbstractFactory/Html/Text.php diff --git a/AbstractFactory/HtmlFactory.php b/Creational/AbstractFactory/HtmlFactory.php similarity index 100% rename from AbstractFactory/HtmlFactory.php rename to Creational/AbstractFactory/HtmlFactory.php diff --git a/AbstractFactory/Json/Picture.php b/Creational/AbstractFactory/Json/Picture.php similarity index 100% rename from AbstractFactory/Json/Picture.php rename to Creational/AbstractFactory/Json/Picture.php diff --git a/AbstractFactory/Json/Text.php b/Creational/AbstractFactory/Json/Text.php similarity index 100% rename from AbstractFactory/Json/Text.php rename to Creational/AbstractFactory/Json/Text.php diff --git a/AbstractFactory/JsonFactory.php b/Creational/AbstractFactory/JsonFactory.php similarity index 100% rename from AbstractFactory/JsonFactory.php rename to Creational/AbstractFactory/JsonFactory.php diff --git a/AbstractFactory/MediaInterface.php b/Creational/AbstractFactory/MediaInterface.php similarity index 100% rename from AbstractFactory/MediaInterface.php rename to Creational/AbstractFactory/MediaInterface.php diff --git a/AbstractFactory/Picture.php b/Creational/AbstractFactory/Picture.php similarity index 100% rename from AbstractFactory/Picture.php rename to Creational/AbstractFactory/Picture.php diff --git a/AbstractFactory/README.md b/Creational/AbstractFactory/README.md similarity index 100% rename from AbstractFactory/README.md rename to Creational/AbstractFactory/README.md diff --git a/Tests/AbstractFactory/AbstractFactoryTest.php b/Creational/AbstractFactory/Test/AbstractFactoryTest.php similarity index 100% rename from Tests/AbstractFactory/AbstractFactoryTest.php rename to Creational/AbstractFactory/Test/AbstractFactoryTest.php diff --git a/AbstractFactory/Text.php b/Creational/AbstractFactory/Text.php similarity index 100% rename from AbstractFactory/Text.php rename to Creational/AbstractFactory/Text.php diff --git a/Builder/BikeBuilder.php b/Creational/Builder/BikeBuilder.php similarity index 100% rename from Builder/BikeBuilder.php rename to Creational/Builder/BikeBuilder.php diff --git a/Builder/BuilderInterface.php b/Creational/Builder/BuilderInterface.php similarity index 100% rename from Builder/BuilderInterface.php rename to Creational/Builder/BuilderInterface.php diff --git a/Builder/CarBuilder.php b/Creational/Builder/CarBuilder.php similarity index 100% rename from Builder/CarBuilder.php rename to Creational/Builder/CarBuilder.php diff --git a/Builder/Director.php b/Creational/Builder/Director.php similarity index 100% rename from Builder/Director.php rename to Creational/Builder/Director.php diff --git a/Builder/Parts/Bike.php b/Creational/Builder/Parts/Bike.php similarity index 100% rename from Builder/Parts/Bike.php rename to Creational/Builder/Parts/Bike.php diff --git a/Builder/Parts/Car.php b/Creational/Builder/Parts/Car.php similarity index 100% rename from Builder/Parts/Car.php rename to Creational/Builder/Parts/Car.php diff --git a/Builder/Parts/Door.php b/Creational/Builder/Parts/Door.php similarity index 100% rename from Builder/Parts/Door.php rename to Creational/Builder/Parts/Door.php diff --git a/Builder/Parts/Engine.php b/Creational/Builder/Parts/Engine.php similarity index 100% rename from Builder/Parts/Engine.php rename to Creational/Builder/Parts/Engine.php diff --git a/Builder/Parts/README.md b/Creational/Builder/Parts/README.md similarity index 100% rename from Builder/Parts/README.md rename to Creational/Builder/Parts/README.md diff --git a/Builder/Parts/Vehicle.php b/Creational/Builder/Parts/Vehicle.php similarity index 100% rename from Builder/Parts/Vehicle.php rename to Creational/Builder/Parts/Vehicle.php diff --git a/Builder/Parts/Wheel.php b/Creational/Builder/Parts/Wheel.php similarity index 100% rename from Builder/Parts/Wheel.php rename to Creational/Builder/Parts/Wheel.php diff --git a/Builder/README.md b/Creational/Builder/README.md similarity index 100% rename from Builder/README.md rename to Creational/Builder/README.md diff --git a/Tests/Builder/DirectorTest.php b/Creational/Builder/Test/DirectorTest.php similarity index 100% rename from Tests/Builder/DirectorTest.php rename to Creational/Builder/Test/DirectorTest.php diff --git a/FactoryMethod/Bicycle.php b/Creational/FactoryMethod/Bicycle.php similarity index 100% rename from FactoryMethod/Bicycle.php rename to Creational/FactoryMethod/Bicycle.php diff --git a/FactoryMethod/FactoryMethod.php b/Creational/FactoryMethod/FactoryMethod.php similarity index 100% rename from FactoryMethod/FactoryMethod.php rename to Creational/FactoryMethod/FactoryMethod.php diff --git a/FactoryMethod/Ferrari.php b/Creational/FactoryMethod/Ferrari.php similarity index 100% rename from FactoryMethod/Ferrari.php rename to Creational/FactoryMethod/Ferrari.php diff --git a/FactoryMethod/GermanFactory.php b/Creational/FactoryMethod/GermanFactory.php similarity index 100% rename from FactoryMethod/GermanFactory.php rename to Creational/FactoryMethod/GermanFactory.php diff --git a/FactoryMethod/ItalianFactory.php b/Creational/FactoryMethod/ItalianFactory.php similarity index 100% rename from FactoryMethod/ItalianFactory.php rename to Creational/FactoryMethod/ItalianFactory.php diff --git a/FactoryMethod/Porsche.php b/Creational/FactoryMethod/Porsche.php similarity index 100% rename from FactoryMethod/Porsche.php rename to Creational/FactoryMethod/Porsche.php diff --git a/FactoryMethod/README.md b/Creational/FactoryMethod/README.md similarity index 100% rename from FactoryMethod/README.md rename to Creational/FactoryMethod/README.md diff --git a/Tests/FactoryMethod/FactoryMethodTest.php b/Creational/FactoryMethod/Test/FactoryMethodTest.php similarity index 100% rename from Tests/FactoryMethod/FactoryMethodTest.php rename to Creational/FactoryMethod/Test/FactoryMethodTest.php diff --git a/FactoryMethod/VehicleInterface.php b/Creational/FactoryMethod/VehicleInterface.php similarity index 100% rename from FactoryMethod/VehicleInterface.php rename to Creational/FactoryMethod/VehicleInterface.php diff --git a/Multiton/Multiton.php b/Creational/Multiton/Multiton.php similarity index 100% rename from Multiton/Multiton.php rename to Creational/Multiton/Multiton.php diff --git a/Multiton/README.md b/Creational/Multiton/README.md similarity index 100% rename from Multiton/README.md rename to Creational/Multiton/README.md diff --git a/Prototype/BarBookPrototype.php b/Creational/Prototype/BarBookPrototype.php similarity index 100% rename from Prototype/BarBookPrototype.php rename to Creational/Prototype/BarBookPrototype.php diff --git a/Prototype/BookPrototype.php b/Creational/Prototype/BookPrototype.php similarity index 100% rename from Prototype/BookPrototype.php rename to Creational/Prototype/BookPrototype.php diff --git a/Prototype/FooBookPrototype.php b/Creational/Prototype/FooBookPrototype.php similarity index 100% rename from Prototype/FooBookPrototype.php rename to Creational/Prototype/FooBookPrototype.php diff --git a/Prototype/README.md b/Creational/Prototype/README.md similarity index 100% rename from Prototype/README.md rename to Creational/Prototype/README.md diff --git a/Prototype/index.php b/Creational/Prototype/index.php similarity index 100% rename from Prototype/index.php rename to Creational/Prototype/index.php diff --git a/SimpleFactory/Bicycle.php b/Creational/SimpleFactory/Bicycle.php similarity index 100% rename from SimpleFactory/Bicycle.php rename to Creational/SimpleFactory/Bicycle.php diff --git a/SimpleFactory/ConcreteFactory.php b/Creational/SimpleFactory/ConcreteFactory.php similarity index 100% rename from SimpleFactory/ConcreteFactory.php rename to Creational/SimpleFactory/ConcreteFactory.php diff --git a/SimpleFactory/README.md b/Creational/SimpleFactory/README.md similarity index 100% rename from SimpleFactory/README.md rename to Creational/SimpleFactory/README.md diff --git a/SimpleFactory/Scooter.php b/Creational/SimpleFactory/Scooter.php similarity index 100% rename from SimpleFactory/Scooter.php rename to Creational/SimpleFactory/Scooter.php diff --git a/Tests/SimpleFactory/SimpleFactoryTest.php b/Creational/SimpleFactory/Test/SimpleFactoryTest.php similarity index 100% rename from Tests/SimpleFactory/SimpleFactoryTest.php rename to Creational/SimpleFactory/Test/SimpleFactoryTest.php diff --git a/SimpleFactory/VehicleInterface.php b/Creational/SimpleFactory/VehicleInterface.php similarity index 100% rename from SimpleFactory/VehicleInterface.php rename to Creational/SimpleFactory/VehicleInterface.php diff --git a/Singleton/README.md b/Creational/Singleton/README.md similarity index 100% rename from Singleton/README.md rename to Creational/Singleton/README.md diff --git a/Singleton/Singleton.php b/Creational/Singleton/Singleton.php similarity index 100% rename from Singleton/Singleton.php rename to Creational/Singleton/Singleton.php diff --git a/Tests/Singleton/SingletonTest.php b/Creational/Singleton/Test/SingletonTest.php similarity index 100% rename from Tests/Singleton/SingletonTest.php rename to Creational/Singleton/Test/SingletonTest.php diff --git a/StaticFactory/FormatNumber.php b/Creational/StaticFactory/FormatNumber.php similarity index 100% rename from StaticFactory/FormatNumber.php rename to Creational/StaticFactory/FormatNumber.php diff --git a/StaticFactory/FormatString.php b/Creational/StaticFactory/FormatString.php similarity index 100% rename from StaticFactory/FormatString.php rename to Creational/StaticFactory/FormatString.php diff --git a/StaticFactory/FormatterInterface.php b/Creational/StaticFactory/FormatterInterface.php similarity index 100% rename from StaticFactory/FormatterInterface.php rename to Creational/StaticFactory/FormatterInterface.php diff --git a/StaticFactory/README.md b/Creational/StaticFactory/README.md similarity index 100% rename from StaticFactory/README.md rename to Creational/StaticFactory/README.md diff --git a/StaticFactory/StaticFactory.php b/Creational/StaticFactory/StaticFactory.php similarity index 100% rename from StaticFactory/StaticFactory.php rename to Creational/StaticFactory/StaticFactory.php diff --git a/Tests/StaticFactory/StaticFactoryTest.php b/Creational/StaticFactory/Test/StaticFactoryTest.php similarity index 100% rename from Tests/StaticFactory/StaticFactoryTest.php rename to Creational/StaticFactory/Test/StaticFactoryTest.php diff --git a/Delegation/JuniorDeveloper.php b/More/Delegation/JuniorDeveloper.php similarity index 100% rename from Delegation/JuniorDeveloper.php rename to More/Delegation/JuniorDeveloper.php diff --git a/Delegation/TeamLead.php b/More/Delegation/TeamLead.php similarity index 100% rename from Delegation/TeamLead.php rename to More/Delegation/TeamLead.php diff --git a/Tests/Delegation/DelegationTest.php b/More/Delegation/Test/DelegationTest.php similarity index 100% rename from Tests/Delegation/DelegationTest.php rename to More/Delegation/Test/DelegationTest.php diff --git a/Delegation/Usage.php b/More/Delegation/Usage.php similarity index 100% rename from Delegation/Usage.php rename to More/Delegation/Usage.php diff --git a/ServiceLocator/DatabaseService.php b/More/ServiceLocator/DatabaseService.php similarity index 100% rename from ServiceLocator/DatabaseService.php rename to More/ServiceLocator/DatabaseService.php diff --git a/ServiceLocator/DatabaseServiceInterface.php b/More/ServiceLocator/DatabaseServiceInterface.php similarity index 100% rename from ServiceLocator/DatabaseServiceInterface.php rename to More/ServiceLocator/DatabaseServiceInterface.php diff --git a/ServiceLocator/LogService.php b/More/ServiceLocator/LogService.php similarity index 100% rename from ServiceLocator/LogService.php rename to More/ServiceLocator/LogService.php diff --git a/ServiceLocator/LogServiceInterface.php b/More/ServiceLocator/LogServiceInterface.php similarity index 100% rename from ServiceLocator/LogServiceInterface.php rename to More/ServiceLocator/LogServiceInterface.php diff --git a/ServiceLocator/README.md b/More/ServiceLocator/README.md similarity index 100% rename from ServiceLocator/README.md rename to More/ServiceLocator/README.md diff --git a/ServiceLocator/ServiceLocator.php b/More/ServiceLocator/ServiceLocator.php similarity index 100% rename from ServiceLocator/ServiceLocator.php rename to More/ServiceLocator/ServiceLocator.php diff --git a/ServiceLocator/ServiceLocatorInterface.php b/More/ServiceLocator/ServiceLocatorInterface.php similarity index 100% rename from ServiceLocator/ServiceLocatorInterface.php rename to More/ServiceLocator/ServiceLocatorInterface.php diff --git a/Tests/ServiceLocator/ServiceLocatorTest.php b/More/ServiceLocator/Test/ServiceLocatorTest.php similarity index 100% rename from Tests/ServiceLocator/ServiceLocatorTest.php rename to More/ServiceLocator/Test/ServiceLocatorTest.php diff --git a/Adapter/Book.php b/Structural/Adapter/Book.php similarity index 100% rename from Adapter/Book.php rename to Structural/Adapter/Book.php diff --git a/Adapter/EBookAdapter.php b/Structural/Adapter/EBookAdapter.php similarity index 100% rename from Adapter/EBookAdapter.php rename to Structural/Adapter/EBookAdapter.php diff --git a/Adapter/EBookInterface.php b/Structural/Adapter/EBookInterface.php similarity index 100% rename from Adapter/EBookInterface.php rename to Structural/Adapter/EBookInterface.php diff --git a/Adapter/Kindle.php b/Structural/Adapter/Kindle.php similarity index 100% rename from Adapter/Kindle.php rename to Structural/Adapter/Kindle.php diff --git a/Adapter/PaperBookInterface.php b/Structural/Adapter/PaperBookInterface.php similarity index 100% rename from Adapter/PaperBookInterface.php rename to Structural/Adapter/PaperBookInterface.php diff --git a/Adapter/README.md b/Structural/Adapter/README.md similarity index 100% rename from Adapter/README.md rename to Structural/Adapter/README.md diff --git a/Tests/Adapter/AdapterTest.php b/Structural/Adapter/Test/AdapterTest.php similarity index 100% rename from Tests/Adapter/AdapterTest.php rename to Structural/Adapter/Test/AdapterTest.php diff --git a/Composite/Form.php b/Structural/Composite/Form.php similarity index 100% rename from Composite/Form.php rename to Structural/Composite/Form.php diff --git a/Composite/FormElement.php b/Structural/Composite/FormElement.php similarity index 100% rename from Composite/FormElement.php rename to Structural/Composite/FormElement.php diff --git a/Composite/InputElement.php b/Structural/Composite/InputElement.php similarity index 100% rename from Composite/InputElement.php rename to Structural/Composite/InputElement.php diff --git a/Composite/README.md b/Structural/Composite/README.md similarity index 100% rename from Composite/README.md rename to Structural/Composite/README.md diff --git a/Tests/Composite/FormTest.php b/Structural/Composite/Test/FormTest.php similarity index 100% rename from Tests/Composite/FormTest.php rename to Structural/Composite/Test/FormTest.php diff --git a/Composite/TextElement.php b/Structural/Composite/TextElement.php similarity index 100% rename from Composite/TextElement.php rename to Structural/Composite/TextElement.php diff --git a/DataMapper/README.md b/Structural/DataMapper/README.md similarity index 100% rename from DataMapper/README.md rename to Structural/DataMapper/README.md diff --git a/Tests/DataMapper/UserMapperTest.php b/Structural/DataMapper/Test/UserMapperTest.php similarity index 100% rename from Tests/DataMapper/UserMapperTest.php rename to Structural/DataMapper/Test/UserMapperTest.php diff --git a/DataMapper/User.php b/Structural/DataMapper/User.php similarity index 100% rename from DataMapper/User.php rename to Structural/DataMapper/User.php diff --git a/DataMapper/UserMapper.php b/Structural/DataMapper/UserMapper.php similarity index 100% rename from DataMapper/UserMapper.php rename to Structural/DataMapper/UserMapper.php diff --git a/Decorator/Decorator.php b/Structural/Decorator/Decorator.php similarity index 100% rename from Decorator/Decorator.php rename to Structural/Decorator/Decorator.php diff --git a/Decorator/README.md b/Structural/Decorator/README.md similarity index 100% rename from Decorator/README.md rename to Structural/Decorator/README.md diff --git a/Decorator/RenderInJson.php b/Structural/Decorator/RenderInJson.php similarity index 100% rename from Decorator/RenderInJson.php rename to Structural/Decorator/RenderInJson.php diff --git a/Decorator/RenderInXml.php b/Structural/Decorator/RenderInXml.php similarity index 100% rename from Decorator/RenderInXml.php rename to Structural/Decorator/RenderInXml.php diff --git a/Decorator/RendererInterface.php b/Structural/Decorator/RendererInterface.php similarity index 100% rename from Decorator/RendererInterface.php rename to Structural/Decorator/RendererInterface.php diff --git a/Tests/Decorator/DecoratorTest.php b/Structural/Decorator/Test/DecoratorTest.php similarity index 100% rename from Tests/Decorator/DecoratorTest.php rename to Structural/Decorator/Test/DecoratorTest.php diff --git a/Decorator/Webservice.php b/Structural/Decorator/Webservice.php similarity index 100% rename from Decorator/Webservice.php rename to Structural/Decorator/Webservice.php diff --git a/DependencyInjection/AbstractConfig.php b/Structural/DependencyInjection/AbstractConfig.php similarity index 100% rename from DependencyInjection/AbstractConfig.php rename to Structural/DependencyInjection/AbstractConfig.php diff --git a/DependencyInjection/ArrayConfig.php b/Structural/DependencyInjection/ArrayConfig.php similarity index 100% rename from DependencyInjection/ArrayConfig.php rename to Structural/DependencyInjection/ArrayConfig.php diff --git a/DependencyInjection/Connection.php b/Structural/DependencyInjection/Connection.php similarity index 100% rename from DependencyInjection/Connection.php rename to Structural/DependencyInjection/Connection.php diff --git a/DependencyInjection/Parameters.php b/Structural/DependencyInjection/Parameters.php similarity index 100% rename from DependencyInjection/Parameters.php rename to Structural/DependencyInjection/Parameters.php diff --git a/DependencyInjection/README.md b/Structural/DependencyInjection/README.md similarity index 100% rename from DependencyInjection/README.md rename to Structural/DependencyInjection/README.md diff --git a/Tests/DependencyInjection/DependencyInjectionTest.php b/Structural/DependencyInjection/Test/DependencyInjectionTest.php similarity index 100% rename from Tests/DependencyInjection/DependencyInjectionTest.php rename to Structural/DependencyInjection/Test/DependencyInjectionTest.php diff --git a/Tests/DependencyInjection/config.php b/Structural/DependencyInjection/Test/config.php similarity index 100% rename from Tests/DependencyInjection/config.php rename to Structural/DependencyInjection/Test/config.php diff --git a/Facade/BiosInterface.php b/Structural/Facade/BiosInterface.php similarity index 100% rename from Facade/BiosInterface.php rename to Structural/Facade/BiosInterface.php diff --git a/Facade/Facade.php b/Structural/Facade/Facade.php similarity index 100% rename from Facade/Facade.php rename to Structural/Facade/Facade.php diff --git a/Facade/OsInterface.php b/Structural/Facade/OsInterface.php similarity index 100% rename from Facade/OsInterface.php rename to Structural/Facade/OsInterface.php diff --git a/Facade/README.md b/Structural/Facade/README.md similarity index 100% rename from Facade/README.md rename to Structural/Facade/README.md diff --git a/Tests/Facade/FacadeTest.php b/Structural/Facade/Test/FacadeTest.php similarity index 100% rename from Tests/Facade/FacadeTest.php rename to Structural/Facade/Test/FacadeTest.php diff --git a/FluentInterface/README.md b/Structural/FluentInterface/README.md similarity index 100% rename from FluentInterface/README.md rename to Structural/FluentInterface/README.md diff --git a/FluentInterface/SQL.php b/Structural/FluentInterface/SQL.php similarity index 100% rename from FluentInterface/SQL.php rename to Structural/FluentInterface/SQL.php diff --git a/Tests/FluentInterface/FluentInterfaceTest.php b/Structural/FluentInterface/Test/FluentInterfaceTest.php similarity index 100% rename from Tests/FluentInterface/FluentInterfaceTest.php rename to Structural/FluentInterface/Test/FluentInterfaceTest.php diff --git a/Proxy/README.md b/Structural/Proxy/README.md similarity index 100% rename from Proxy/README.md rename to Structural/Proxy/README.md diff --git a/Proxy/Record.php b/Structural/Proxy/Record.php similarity index 100% rename from Proxy/Record.php rename to Structural/Proxy/Record.php diff --git a/Proxy/RecordProxy.php b/Structural/Proxy/RecordProxy.php similarity index 100% rename from Proxy/RecordProxy.php rename to Structural/Proxy/RecordProxy.php diff --git a/Registry/README.md b/Structural/Registry/README.md similarity index 100% rename from Registry/README.md rename to Structural/Registry/README.md diff --git a/Registry/Registry.php b/Structural/Registry/Registry.php similarity index 100% rename from Registry/Registry.php rename to Structural/Registry/Registry.php diff --git a/Registry/index.php b/Structural/Registry/index.php similarity index 100% rename from Registry/index.php rename to Structural/Registry/index.php From 3e515daa0f4b85ea0edd8f7aeeb9b8806cb41076 Mon Sep 17 00:00:00 2001 From: Antonio Spinelli Date: Mon, 24 Mar 2014 09:14:05 -0300 Subject: [PATCH 02/17] Behavioral\Command restructured --- Behavioral/Command/CommandInterface.php | 2 +- Behavioral/Command/HelloCommand.php | 2 +- Behavioral/Command/Invoker.php | 2 +- Behavioral/Command/Receiver.php | 2 +- .../Command/{Test => Tests}/CommandTest.php | 16 +++++++++++----- 5 files changed, 15 insertions(+), 9 deletions(-) rename Behavioral/Command/{Test => Tests}/CommandTest.php (65%) diff --git a/Behavioral/Command/CommandInterface.php b/Behavioral/Command/CommandInterface.php index ebdbb85..ad9117b 100644 --- a/Behavioral/Command/CommandInterface.php +++ b/Behavioral/Command/CommandInterface.php @@ -1,6 +1,6 @@ invoker = new Invoker(); $this->receiver = new Receiver(); } From d225a43de720b311bca3a3bcf69d9d31a8590e82 Mon Sep 17 00:00:00 2001 From: Antonio Spinelli Date: Mon, 24 Mar 2014 10:40:08 -0300 Subject: [PATCH 03/17] Behavioral\Iterator restructured --- Behavioral/Iterator/Book.php | 32 ++++++ Behavioral/Iterator/BookList.php | 42 ++++++++ Behavioral/Iterator/BookListIterator.php | 77 ++++++++++++++ .../Iterator/BookListReverseIterator.php | 23 ++++ Behavioral/Iterator/File.php | 39 ------- Behavioral/Iterator/Row.php | 27 ----- Behavioral/Iterator/RowSet.php | 100 ------------------ Behavioral/Iterator/Tests/IteratorTest.php | 66 ++++++++++++ 8 files changed, 240 insertions(+), 166 deletions(-) create mode 100644 Behavioral/Iterator/Book.php create mode 100644 Behavioral/Iterator/BookList.php create mode 100644 Behavioral/Iterator/BookListIterator.php create mode 100644 Behavioral/Iterator/BookListReverseIterator.php delete mode 100644 Behavioral/Iterator/File.php delete mode 100644 Behavioral/Iterator/Row.php delete mode 100644 Behavioral/Iterator/RowSet.php create mode 100644 Behavioral/Iterator/Tests/IteratorTest.php diff --git a/Behavioral/Iterator/Book.php b/Behavioral/Iterator/Book.php new file mode 100644 index 0000000..a0d1114 --- /dev/null +++ b/Behavioral/Iterator/Book.php @@ -0,0 +1,32 @@ +author = $author; + $this->title = $title; + } + + public function getAuthor() + { + return $this->author; + } + + public function getTitle() + { + return $this->title; + } + + public function getAuthorAndTitle() + { + return $this->getTitle() . ' by ' . $this->getAuthor(); + } +} diff --git a/Behavioral/Iterator/BookList.php b/Behavioral/Iterator/BookList.php new file mode 100644 index 0000000..eb9a8be --- /dev/null +++ b/Behavioral/Iterator/BookList.php @@ -0,0 +1,42 @@ +count()) { + return $this->books[$bookNumberToGet]; + } + + return NULL; + } + + public function addBook(Book $book) + { + $this->books[] = $book; + + return $this->count(); + } + + public function removeBook(Book $bookToRemove) + { + foreach ($this as $key => $book) { + /** @var Book $book */ + if ($book->getAuthorAndTitle() === $bookToRemove->getAuthorAndTitle()) { + unset($this->books[$key]); + } + } + + return $this->count(); + } + + public function count() + { + return count($this->books); + } +} diff --git a/Behavioral/Iterator/BookListIterator.php b/Behavioral/Iterator/BookListIterator.php new file mode 100644 index 0000000..d0992c6 --- /dev/null +++ b/Behavioral/Iterator/BookListIterator.php @@ -0,0 +1,77 @@ +bookList = $bookList; + } + + /** + * Return the current book + * @link http://php.net/manual/en/iterator.current.php + * @return Book Can return any type. + */ + public function current() + { + return $this->bookList->getBook($this->currentBook); + } + + /** + * (PHP 5 >= 5.0.0)
+ * Move forward to next element + * @link http://php.net/manual/en/iterator.next.php + * @return void Any returned value is ignored. + */ + public function next() + { + $this->currentBook++; + } + + /** + * (PHP 5 >= 5.0.0)
+ * Return the key of the current element + * @link http://php.net/manual/en/iterator.key.php + * @return mixed scalar on success, or null on failure. + */ + public function key() + { + return $this->currentBook; + } + + /** + * (PHP 5 >= 5.0.0)
+ * Checks if current position is valid + * @link http://php.net/manual/en/iterator.valid.php + * @return boolean The return value will be casted to boolean and then evaluated. + * Returns true on success or false on failure. + */ + public function valid() + { + return $this->currentBook < $this->bookList->count(); + } + + /** + * (PHP 5 >= 5.0.0)
+ * Rewind the Iterator to the first element + * @link http://php.net/manual/en/iterator.rewind.php + * @return void Any returned value is ignored. + */ + public function rewind() + { + $this->currentBook = 0; + } +} \ No newline at end of file diff --git a/Behavioral/Iterator/BookListReverseIterator.php b/Behavioral/Iterator/BookListReverseIterator.php new file mode 100644 index 0000000..2e38f63 --- /dev/null +++ b/Behavioral/Iterator/BookListReverseIterator.php @@ -0,0 +1,23 @@ +bookList = $bookList; + $this->currentBook = $this->bookList->count() - 1; + } + + public function next() + { + $this->currentBook--; + } + + public function valid() + { + return 0 <= $this->currentBook; + } +} \ No newline at end of file diff --git a/Behavioral/Iterator/File.php b/Behavioral/Iterator/File.php deleted file mode 100644 index e2e6a3d..0000000 --- a/Behavioral/Iterator/File.php +++ /dev/null @@ -1,39 +0,0 @@ -rowSet = new Rowset($this); - } - - /** - * processes the rowSet - */ - public function process() - { - // this is the place to show how using an iterator, with foreach - // See the CardGame.php file - $this->rowSet->process(); - } -} diff --git a/Behavioral/Iterator/Row.php b/Behavioral/Iterator/Row.php deleted file mode 100644 index df4002d..0000000 --- a/Behavioral/Iterator/Row.php +++ /dev/null @@ -1,27 +0,0 @@ -data = $data; - } - - /** - * {@inheritdoc} - */ - public function process() - { - // do some fancy things here ... - } -} diff --git a/Behavioral/Iterator/RowSet.php b/Behavioral/Iterator/RowSet.php deleted file mode 100644 index f1ef5d7..0000000 --- a/Behavioral/Iterator/RowSet.php +++ /dev/null @@ -1,100 +0,0 @@ -file = $file; - } - - /** - * composite pattern: run through all rows and process them - * - * @return void - */ - public function process() - { - // this actually calls rewind(), { next(), valid(), key() and current() :} - /** - * THE key feature of the Iterator Pattern is to provide a *public contract* - * to iterate on a collection without knowing how items are handled inside - * the collection. It is not just an easy way to use "foreach" - * - * One cannot see the point of iterator pattern if you iterate on $this. - * This example is unclear and mixed with some Composite pattern ideas. - */ - foreach ($this as $line => $row) { - $row->process(); - } - } - - /** - * {@inheritdoc} - */ - public function rewind() - { - // seek to first line from $this->file - } - - /** - * {@inheritdoc} - */ - public function next() - { - // read the next line from $this->file - if (!$eof) { - $data = ''; // get the line - $this->currentRow = new Row($data); - } else { - $this->currentRow = null; - } - } - - /** - * {@inheritdoc} - */ - public function current() - { - return $this->currentRow; - } - - /** - * {@inheritdoc} - */ - public function valid() - { - return null !== $this->currentRow; - } - - /** - * {@inheritdoc} - */ - public function key() - { - // you would want to increment this in next() or whatsoever - return $this->lineNumber; - } -} diff --git a/Behavioral/Iterator/Tests/IteratorTest.php b/Behavioral/Iterator/Tests/IteratorTest.php new file mode 100644 index 0000000..4bc58f0 --- /dev/null +++ b/Behavioral/Iterator/Tests/IteratorTest.php @@ -0,0 +1,66 @@ +bookList = new BookList(); + $this->bookList->addBook(new Book('Learning PHP Design Patterns', 'William Sanders')); + $this->bookList->addBook(new Book('Professional Php Design Patterns', 'Aaron Saray')); + $this->bookList->addBook(new Book('Clean Code', 'Robert C. Martin')); + } + + public function expectedAuthors() + { + return array( + array( + array( + 'Learning PHP Design Patterns by William Sanders', + 'Professional Php Design Patterns by Aaron Saray', + 'Clean Code by Robert C. Martin' + ) + ), + ); + } + + /** + * @dataProvider expectedAuthors + */ + public function testUseAIteratorAndValidateAuthors($expected) + { + $iterator = new BookListIterator($this->bookList); + + while ($iterator->valid()) { + $expectedBook = array_shift($expected); + $this->assertEquals($expectedBook, $iterator->current()->getAuthorAndTitle()); + $iterator->next(); + } + } + + /** + * @dataProvider expectedAuthors + */ + public function testUseAReverseIteratorAndValidateAuthors($expected) + { + $iterator = new BookListReverseIterator($this->bookList); + + while ($iterator->valid()) { + $expectedBook = array_pop($expected); + $this->assertEquals($expectedBook, $iterator->current()->getAuthorAndTitle()); + $iterator->next(); + } + } +} \ No newline at end of file From 646e0e2fd9b99a95eb0cf17a150f21944d310fa8 Mon Sep 17 00:00:00 2001 From: Antonio Spinelli Date: Tue, 15 Apr 2014 22:25:48 -0300 Subject: [PATCH 04/17] it was created the Behavioral namespace and append its patterns --- .../{Tests => }/ChainTest.php | 2 +- Behavioral/Command/{Tests => }/CommandTest.php | 2 +- .../Iterator/{Tests => }/IteratorTest.php | 2 +- Behavioral/Mediator/Colleague.php | 2 +- Behavioral/Mediator/Mediator.php | 18 +++++++++++++----- Behavioral/Mediator/MediatorInterface.php | 2 +- .../Mediator/{Test => }/MediatorTest.php | 8 ++++---- Behavioral/Mediator/Subsystem/Client.php | 4 ++-- Behavioral/Mediator/Subsystem/Database.php | 4 ++-- Behavioral/Mediator/Subsystem/Server.php | 4 ++-- Behavioral/NullObject/LoggerInterface.php | 2 +- .../NullObject/{Test => }/LoggerTest.php | 10 +++++----- Behavioral/NullObject/NullLogger.php | 2 +- Behavioral/NullObject/PrintLogger.php | 2 +- Behavioral/NullObject/Service.php | 2 +- .../Observer/{Test => }/ObserverTest.php | 8 ++++---- Behavioral/Observer/User.php | 2 +- Behavioral/Observer/UserObserver.php | 2 +- .../Specification/AbstractSpecification.php | 2 +- Behavioral/Specification/Either.php | 2 +- Behavioral/Specification/Item.php | 2 +- Behavioral/Specification/Not.php | 2 +- Behavioral/Specification/Plus.php | 2 +- .../Specification/PriceSpecification.php | 2 +- .../Specification/SpecificationInterface.php | 2 +- .../{Test => }/SpecificationTest.php | 6 +++--- Behavioral/State/CreateOrder.php | 2 +- Behavioral/State/OrderController.php | 2 +- Behavioral/State/OrderFactory.php | 4 ++-- Behavioral/State/OrderInterface.php | 2 +- Behavioral/State/ShippingOrder.php | 2 +- Behavioral/Strategy/ComparatorInterface.php | 2 +- Behavioral/Strategy/DateComparator.php | 2 +- Behavioral/Strategy/IdComparator.php | 2 +- Behavioral/Strategy/ObjectCollection.php | 2 +- .../Strategy/StrategyTest.php | 10 +++++----- Behavioral/TemplateMethod/BeachJourney.php | 2 +- Behavioral/TemplateMethod/CityJourney.php | 2 +- Behavioral/TemplateMethod/Journey.php | 2 +- .../TemplateMethod/{Test => }/JourneyTest.php | 6 +++--- Behavioral/Visitor/Group.php | 2 +- Behavioral/Visitor/Role.php | 4 ++-- Behavioral/Visitor/RolePrintVisitor.php | 2 +- Behavioral/Visitor/RoleVisitorInterface.php | 6 +++--- Behavioral/Visitor/User.php | 2 +- Behavioral/Visitor/{Test => }/VisitorTest.php | 4 ++-- phpunit.xml.dist | 5 ++++- 47 files changed, 88 insertions(+), 77 deletions(-) rename Behavioral/ChainOfResponsibilities/{Tests => }/ChainTest.php (97%) rename Behavioral/Command/{Tests => }/CommandTest.php (93%) rename Behavioral/Iterator/{Tests => }/IteratorTest.php (97%) rename Behavioral/Mediator/{Test => }/MediatorTest.php (78%) rename Behavioral/NullObject/{Test => }/LoggerTest.php (65%) rename Behavioral/Observer/{Test => }/ObserverTest.php (83%) rename Behavioral/Specification/{Test => }/SpecificationTest.php (94%) rename {Tests => Behavioral}/Strategy/StrategyTest.php (86%) rename Behavioral/TemplateMethod/{Test => }/JourneyTest.php (87%) rename Behavioral/Visitor/{Test => }/VisitorTest.php (87%) diff --git a/Behavioral/ChainOfResponsibilities/Tests/ChainTest.php b/Behavioral/ChainOfResponsibilities/ChainTest.php similarity index 97% rename from Behavioral/ChainOfResponsibilities/Tests/ChainTest.php rename to Behavioral/ChainOfResponsibilities/ChainTest.php index 4b867c5..23e5625 100644 --- a/Behavioral/ChainOfResponsibilities/Tests/ChainTest.php +++ b/Behavioral/ChainOfResponsibilities/ChainTest.php @@ -1,6 +1,6 @@ expectOutputString('We are in DesignPatterns\NullObject\Service::doSomething'); + $this->expectOutputString('We are in DesignPatterns\Behavioral\NullObject\Service::doSomething'); $service->doSomething(); } } diff --git a/Behavioral/NullObject/NullLogger.php b/Behavioral/NullObject/NullLogger.php index 7f013dc..49ff51e 100644 --- a/Behavioral/NullObject/NullLogger.php +++ b/Behavioral/NullObject/NullLogger.php @@ -1,6 +1,6 @@ expectOutputString('DesignPatterns\Observer\User has been updated'); + $this->expectOutputString('DesignPatterns\Behavioral\Observer\User has been updated'); $subject = new User(); $subject->attach($this->observer); diff --git a/Behavioral/Observer/User.php b/Behavioral/Observer/User.php index 3ee3fba..5b6fb4c 100644 --- a/Behavioral/Observer/User.php +++ b/Behavioral/Observer/User.php @@ -1,6 +1,6 @@ getMockForAbstractClass('DesignPatterns\TemplateMethod\Journey'); + $journey = $this->getMockForAbstractClass('DesignPatterns\Behavioral\TemplateMethod\Journey'); $journey->expects($this->once()) ->method('enjoyVacation') ->will($this->returnCallback(array($this, 'mockUpVacation'))); diff --git a/Behavioral/Visitor/Group.php b/Behavioral/Visitor/Group.php index 5d47d6a..3990f9c 100644 --- a/Behavioral/Visitor/Group.php +++ b/Behavioral/Visitor/Group.php @@ -1,6 +1,6 @@ getMockForAbstractClass('DesignPatterns\Visitor\Role'); + $mock = $this->getMockForAbstractClass('DesignPatterns\Behavioral\Visitor\Role'); $mock->accept($this->visitor); } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index c69c7f5..391c078 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -3,7 +3,10 @@ - ./Tests + ./Behavioral/*/*Test.php + ./Creational/*/*/Test.php + ./More/*/*/Test.php + ./Structural/*/*/Test.php From 7bf6593e3f827e102fd683cb86f46da457ec4576 Mon Sep 17 00:00:00 2001 From: Antonio Spinelli Date: Tue, 15 Apr 2014 22:59:59 -0300 Subject: [PATCH 05/17] it was created the Creational namespace and append its patterns --- Creational/AbstractFactory/AbstractFactory.php | 2 +- .../{Test => }/AbstractFactoryTest.php | 10 +++++----- Creational/AbstractFactory/Html/Picture.php | 4 ++-- Creational/AbstractFactory/Html/Text.php | 4 ++-- Creational/AbstractFactory/HtmlFactory.php | 2 +- Creational/AbstractFactory/Json/Picture.php | 4 ++-- Creational/AbstractFactory/Json/Text.php | 4 ++-- Creational/AbstractFactory/JsonFactory.php | 2 +- Creational/AbstractFactory/MediaInterface.php | 2 +- Creational/AbstractFactory/Picture.php | 2 +- Creational/AbstractFactory/Text.php | 2 +- Creational/Builder/BikeBuilder.php | 2 +- Creational/Builder/BuilderInterface.php | 2 +- Creational/Builder/CarBuilder.php | 2 +- Creational/Builder/Director.php | 2 +- Creational/Builder/{Test => }/DirectorTest.php | 12 ++++++------ Creational/Builder/Parts/Bike.php | 2 +- Creational/Builder/Parts/Car.php | 2 +- Creational/Builder/Parts/Door.php | 2 +- Creational/Builder/Parts/Engine.php | 2 +- Creational/Builder/Parts/Vehicle.php | 2 +- Creational/Builder/Parts/Wheel.php | 2 +- Creational/FactoryMethod/Bicycle.php | 2 +- Creational/FactoryMethod/FactoryMethod.php | 2 +- .../{Test => }/FactoryMethodTest.php | 10 +++++----- Creational/FactoryMethod/Ferrari.php | 2 +- Creational/FactoryMethod/GermanFactory.php | 2 +- Creational/FactoryMethod/ItalianFactory.php | 2 +- Creational/FactoryMethod/Porsche.php | 2 +- Creational/FactoryMethod/VehicleInterface.php | 2 +- Creational/Multiton/Multiton.php | 2 +- {Pool => Creational/Pool}/Pool.php | 2 +- {Tests => Creational}/Pool/PoolTest.php | 8 +++----- {Pool => Creational/Pool}/Processor.php | 2 +- {Pool => Creational/Pool}/README.md | 0 {Pool => Creational/Pool}/Worker.php | 2 +- Creational/Prototype/BarBookPrototype.php | 2 +- Creational/Prototype/BookPrototype.php | 2 +- Creational/Prototype/FooBookPrototype.php | 2 +- Creational/Prototype/index.php | 2 +- Creational/SimpleFactory/Bicycle.php | 2 +- Creational/SimpleFactory/ConcreteFactory.php | 2 +- Creational/SimpleFactory/Scooter.php | 2 +- .../{Test => }/SimpleFactoryTest.php | 6 +++--- Creational/SimpleFactory/VehicleInterface.php | 2 +- Creational/Singleton/Singleton.php | 4 ++-- .../Singleton/{Test => }/SingletonTest.php | 6 +++--- Creational/StaticFactory/FormatNumber.php | 2 +- Creational/StaticFactory/FormatString.php | 2 +- Creational/StaticFactory/FormatterInterface.php | 2 +- Creational/StaticFactory/StaticFactory.php | 2 +- .../{Test => }/StaticFactoryTest.php | 6 +++--- Pool/index.php | 16 ---------------- 53 files changed, 77 insertions(+), 95 deletions(-) rename Creational/AbstractFactory/{Test => }/AbstractFactoryTest.php (74%) rename Creational/Builder/{Test => }/DirectorTest.php (66%) rename Creational/FactoryMethod/{Test => }/FactoryMethodTest.php (75%) rename {Pool => Creational/Pool}/Pool.php (91%) rename {Tests => Creational}/Pool/PoolTest.php (71%) rename {Pool => Creational/Pool}/Processor.php (96%) rename {Pool => Creational/Pool}/README.md (100%) rename {Pool => Creational/Pool}/Worker.php (89%) rename Creational/SimpleFactory/{Test => }/SimpleFactoryTest.php (76%) rename Creational/Singleton/{Test => }/SingletonTest.php (74%) rename Creational/StaticFactory/{Test => }/StaticFactoryTest.php (65%) delete mode 100644 Pool/index.php diff --git a/Creational/AbstractFactory/AbstractFactory.php b/Creational/AbstractFactory/AbstractFactory.php index 481e14e..84b4203 100644 --- a/Creational/AbstractFactory/AbstractFactory.php +++ b/Creational/AbstractFactory/AbstractFactory.php @@ -1,6 +1,6 @@ createText('footnotes') ); - $this->assertContainsOnly('DesignPatterns\AbstractFactory\MediaInterface', $article); + $this->assertContainsOnly('DesignPatterns\Creational\AbstractFactory\MediaInterface', $article); /* this is the time to look at the Builder pattern. This pattern * helps you to create complex object like that article above with diff --git a/Creational/AbstractFactory/Html/Picture.php b/Creational/AbstractFactory/Html/Picture.php index 2e648b0..3f224fc 100644 --- a/Creational/AbstractFactory/Html/Picture.php +++ b/Creational/AbstractFactory/Html/Picture.php @@ -1,8 +1,8 @@ director->build($builder); - $this->assertInstanceOf('DesignPatterns\Builder\Parts\Vehicle', $newVehicle); + $this->assertInstanceOf('DesignPatterns\Creational\Builder\Parts\Vehicle', $newVehicle); } } diff --git a/Creational/Builder/Parts/Bike.php b/Creational/Builder/Parts/Bike.php index 6ffa4e2..307b3e0 100644 --- a/Creational/Builder/Parts/Bike.php +++ b/Creational/Builder/Parts/Bike.php @@ -1,6 +1,6 @@ type as $oneType) { $vehicle = $shop->create($oneType); - $this->assertInstanceOf('DesignPatterns\FactoryMethod\VehicleInterface', $vehicle); + $this->assertInstanceOf('DesignPatterns\Creational\FactoryMethod\VehicleInterface', $vehicle); } } diff --git a/Creational/FactoryMethod/Ferrari.php b/Creational/FactoryMethod/Ferrari.php index f221e42..c905f91 100644 --- a/Creational/FactoryMethod/Ferrari.php +++ b/Creational/FactoryMethod/Ferrari.php @@ -1,6 +1,6 @@ get(); $this->assertEquals(1, $worker->id); @@ -27,6 +26,5 @@ class PoolTest extends \PHPUnit_Framework_TestCase $this->assertEquals(5, $pool->get()->id); $this->assertEquals(1, $pool->get()->id); } - } diff --git a/Pool/Processor.php b/Creational/Pool/Processor.php similarity index 96% rename from Pool/Processor.php rename to Creational/Pool/Processor.php index eabd51d..47523b0 100644 --- a/Pool/Processor.php +++ b/Creational/Pool/Processor.php @@ -1,6 +1,6 @@ factory->createVehicle($type); - $this->assertInstanceOf('DesignPatterns\SimpleFactory\VehicleInterface', $obj); + $this->assertInstanceOf('DesignPatterns\Creational\SimpleFactory\VehicleInterface', $obj); } /** diff --git a/Creational/SimpleFactory/VehicleInterface.php b/Creational/SimpleFactory/VehicleInterface.php index 66dc3fd..eb13a66 100644 --- a/Creational/SimpleFactory/VehicleInterface.php +++ b/Creational/SimpleFactory/VehicleInterface.php @@ -1,6 +1,6 @@ assertInstanceOf('DesignPatterns\Singleton\Singleton', $firstCall); + $this->assertInstanceOf('DesignPatterns\Creational\Singleton\Singleton', $firstCall); $secondCall = Singleton::getInstance(); $this->assertSame($firstCall, $secondCall); } diff --git a/Creational/StaticFactory/FormatNumber.php b/Creational/StaticFactory/FormatNumber.php index 8b20db2..93ac7c7 100644 --- a/Creational/StaticFactory/FormatNumber.php +++ b/Creational/StaticFactory/FormatNumber.php @@ -1,6 +1,6 @@ global => evil diff --git a/Creational/StaticFactory/Test/StaticFactoryTest.php b/Creational/StaticFactory/StaticFactoryTest.php similarity index 65% rename from Creational/StaticFactory/Test/StaticFactoryTest.php rename to Creational/StaticFactory/StaticFactoryTest.php index d85f266..1582e56 100644 --- a/Creational/StaticFactory/Test/StaticFactoryTest.php +++ b/Creational/StaticFactory/StaticFactoryTest.php @@ -1,8 +1,8 @@ assertInstanceOf('DesignPatterns\StaticFactory\FormatterInterface', $obj); + $this->assertInstanceOf('DesignPatterns\Creational\StaticFactory\FormatterInterface', $obj); } } diff --git a/Pool/index.php b/Pool/index.php deleted file mode 100644 index 3059efe..0000000 --- a/Pool/index.php +++ /dev/null @@ -1,16 +0,0 @@ -process('image1.jpg'); -$processor->process('image2.jpg'); -$processor->process('image3.jpg'); -$processor->process('image4.jpg'); -$processor->process('image5.jpg'); -$processor->process('image6.jpg'); -$processor->process('image7.jpg'); -$processor->process('image8.jpg'); From 113f63a54f8f33afc75059c721fe955371279548 Mon Sep 17 00:00:00 2001 From: Antonio Spinelli Date: Tue, 15 Apr 2014 23:14:39 -0300 Subject: [PATCH 06/17] it was created the Structural namespace and append its patterns --- Structural/Adapter/{Test => }/AdapterTest.php | 10 +++++----- Structural/Adapter/Book.php | 2 +- Structural/Adapter/EBookAdapter.php | 2 +- Structural/Adapter/EBookInterface.php | 2 +- Structural/Adapter/Kindle.php | 2 +- Structural/Adapter/PaperBookInterface.php | 2 +- .../{Test/FormTest.php => CompositeTest.php} | 6 +++--- Structural/Composite/Form.php | 2 +- Structural/Composite/FormElement.php | 2 +- Structural/Composite/InputElement.php | 2 +- Structural/Composite/TextElement.php | 2 +- .../UserMapperTest.php => DataMapperTest.php} | 12 ++++++------ Structural/DataMapper/User.php | 2 +- Structural/DataMapper/UserMapper.php | 2 +- Structural/Decorator/Decorator.php | 2 +- .../Decorator/{Test => }/DecoratorTest.php | 12 ++++++------ Structural/Decorator/RenderInJson.php | 2 +- Structural/Decorator/RenderInXml.php | 2 +- Structural/Decorator/RendererInterface.php | 2 +- Structural/Decorator/Webservice.php | 2 +- .../DependencyInjection/AbstractConfig.php | 2 +- Structural/DependencyInjection/ArrayConfig.php | 2 +- Structural/DependencyInjection/Connection.php | 2 +- .../{Test => }/DependencyInjectionTest.php | 10 +++++----- Structural/DependencyInjection/Parameters.php | 2 +- .../DependencyInjection/{Test => }/config.php | 0 Structural/Facade/BiosInterface.php | 2 +- Structural/Facade/Facade.php | 2 +- Structural/Facade/{Test => }/FacadeTest.php | 8 ++++---- Structural/Facade/OsInterface.php | 2 +- .../{Test => }/FluentInterfaceTest.php | 6 +++--- Structural/FluentInterface/SQL.php | 4 ++-- Structural/Proxy/Record.php | 2 +- Structural/Proxy/RecordProxy.php | 2 +- Structural/Registry/Registry.php | 2 +- Structural/Registry/RegistryTest.php | 17 +++++++++++++++++ Structural/Registry/index.php | 9 --------- 37 files changed, 77 insertions(+), 69 deletions(-) rename Structural/Adapter/{Test => }/AdapterTest.php (77%) rename Structural/Composite/{Test/FormTest.php => CompositeTest.php} (77%) rename Structural/DataMapper/{Test/UserMapperTest.php => DataMapperTest.php} (87%) rename Structural/Decorator/{Test => }/DecoratorTest.php (72%) rename Structural/DependencyInjection/{Test => }/DependencyInjectionTest.php (61%) rename Structural/DependencyInjection/{Test => }/config.php (100%) rename Structural/Facade/{Test => }/FacadeTest.php (79%) rename Structural/FluentInterface/{Test => }/FluentInterfaceTest.php (76%) create mode 100644 Structural/Registry/RegistryTest.php delete mode 100644 Structural/Registry/index.php diff --git a/Structural/Adapter/Test/AdapterTest.php b/Structural/Adapter/AdapterTest.php similarity index 77% rename from Structural/Adapter/Test/AdapterTest.php rename to Structural/Adapter/AdapterTest.php index 370a6c3..55cc5e2 100644 --- a/Structural/Adapter/Test/AdapterTest.php +++ b/Structural/Adapter/AdapterTest.php @@ -1,11 +1,11 @@ assertTrue(is_subclass_of('DesignPatterns\Composite\Form', 'DesignPatterns\Composite\FormElement')); + $this->assertTrue(is_subclass_of('DesignPatterns\Structural\Composite\Form', 'DesignPatterns\Structural\Composite\FormElement')); } } diff --git a/Structural/Composite/Form.php b/Structural/Composite/Form.php index 66248c2..fbf3b50 100644 --- a/Structural/Composite/Form.php +++ b/Structural/Composite/Form.php @@ -1,6 +1,6 @@ dbal = $this->getMockBuilder('DesignPatterns\DataMapper\DBAL') + $this->dbal = $this->getMockBuilder('DesignPatterns\Structural\DataMapper\DBAL') ->disableAutoload() ->setMethods(array('insert', 'update', 'find', 'findAll')) ->getMock(); @@ -90,7 +90,7 @@ class UserMapperTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException InvalidArgumentException + * @expectedException \InvalidArgumentException * @expectedExceptionMessage User #404 not found */ public function testNotFound() diff --git a/Structural/DataMapper/User.php b/Structural/DataMapper/User.php index 12f8779..78e60a8 100644 --- a/Structural/DataMapper/User.php +++ b/Structural/DataMapper/User.php @@ -1,6 +1,6 @@ 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() { - $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() { - $mock = $this->getMock('DesignPatterns\Decorator\RendererInterface'); - $dec = $this->getMockForAbstractClass('DesignPatterns\Decorator\Decorator', array($mock)); + $mock = $this->getMock('DesignPatterns\Structural\Decorator\RendererInterface'); + $dec = $this->getMockForAbstractClass('DesignPatterns\Structural\Decorator\Decorator', array($mock)); $this->assertNotNull($dec); } } diff --git a/Structural/Decorator/RenderInJson.php b/Structural/Decorator/RenderInJson.php index 0edc7ea..ebcc577 100644 --- a/Structural/Decorator/RenderInJson.php +++ b/Structural/Decorator/RenderInJson.php @@ -1,6 +1,6 @@ getMockBuilder('DesignPatterns\Facade\BiosInterface') + $bios = $this->getMockBuilder('DesignPatterns\Structural\Facade\BiosInterface') ->setMethods(array('launch', 'execute', 'waitForKeyPress')) ->disableAutoload() ->getMock(); - $operatingSys = $this->getMockBuilder('DesignPatterns\Facade\OsInterface') + $operatingSys = $this->getMockBuilder('DesignPatterns\Structural\Facade\OsInterface') ->setMethods(array('getName')) ->disableAutoload() ->getMock(); diff --git a/Structural/Facade/OsInterface.php b/Structural/Facade/OsInterface.php index e81c7f1..3b09eb1 100644 --- a/Structural/Facade/OsInterface.php +++ b/Structural/Facade/OsInterface.php @@ -1,6 +1,6 @@ select(array('foo', 'bar')) ->from('foobar', 'f') ->where('f.bar = ?') diff --git a/Structural/FluentInterface/SQL.php b/Structural/FluentInterface/SQL.php index 6b7d82d..3afd300 100644 --- a/Structural/FluentInterface/SQL.php +++ b/Structural/FluentInterface/SQL.php @@ -1,11 +1,11 @@ assertInstanceOf('StdClass', $logger); + } +} diff --git a/Structural/Registry/index.php b/Structural/Registry/index.php deleted file mode 100644 index 2b0ecba..0000000 --- a/Structural/Registry/index.php +++ /dev/null @@ -1,9 +0,0 @@ -log('foo'); From 06fc97713a9f5cf170eb05da8537368dd2603384 Mon Sep 17 00:00:00 2001 From: Antonio Spinelli Date: Wed, 16 Apr 2014 14:51:11 -0300 Subject: [PATCH 07/17] add README files --- Behavioral/README.md | 13 +++++++++ Creational/README.md | 11 +++++++ More/README.md | 4 +++ README.md | 69 ++++++++++++++++++++++---------------------- Structural/README.md | 11 +++++++ 5 files changed, 74 insertions(+), 34 deletions(-) create mode 100644 Behavioral/README.md create mode 100644 Creational/README.md create mode 100644 More/README.md create mode 100644 Structural/README.md diff --git a/Behavioral/README.md b/Behavioral/README.md new file mode 100644 index 0000000..470d3fd --- /dev/null +++ b/Behavioral/README.md @@ -0,0 +1,13 @@ +# Behavioral + +* [ChainOfResponsibilities](ChainOfResponsibilities) [:notebook:](http://en.wikipedia.org/wiki/Chain_of_responsibility_pattern) +* [Command](Command) [:notebook:](http://en.wikipedia.org/wiki/Command_pattern) +* [Iterator](Iterator) [:notebook:](http://en.wikipedia.org/wiki/Iterator_pattern) +* [Mediator](Mediator) [:notebook:](http://en.wikipedia.org/wiki/Mediator_pattern) +* [NullObject](NullObject) [:notebook:](http://en.wikipedia.org/wiki/Null_Object_pattern) +* [Observer](Observer) [:notebook:](http://en.wikipedia.org/wiki/Observer_pattern) +* [Specification](Specification) [:notebook:](http://en.wikipedia.org/wiki/Specification_pattern) +* [State](State) [:notebook:](http://en.wikipedia.org/wiki/State_pattern) +* [Strategy](Strategy) [:notebook:](http://en.wikipedia.org/wiki/Strategy_pattern) +* [TemplateMethod](TemplateMethod) [:notebook:](http://en.wikipedia.org/wiki/Template_method_pattern) +* [Visitor](Visitor) [:notebook:](http://en.wikipedia.org/wiki/Visitor_pattern) diff --git a/Creational/README.md b/Creational/README.md new file mode 100644 index 0000000..d31a692 --- /dev/null +++ b/Creational/README.md @@ -0,0 +1,11 @@ +# Creational + +* [AbstractFactory](AbstractFactory) [:notebook:](http://en.wikipedia.org/wiki/Abstract_factory_pattern) +* [Builder](Builder) [:notebook:](http://en.wikipedia.org/wiki/Builder_pattern) +* [FactoryMethod](FactoryMethod) [:notebook:](http://en.wikipedia.org/wiki/Factory_method_pattern) +* [Multiton](Multiton) (is considered an anti-pattern! :no_entry:) +* [Pool](Pool) [:notebook:](http://en.wikipedia.org/wiki/Object_pool_pattern) +* [Prototype](Prototype) [:notebook:](http://en.wikipedia.org/wiki/Prototype_pattern) +* [SimpleFactory](SimpleFactory) +* [Singleton](Singleton) [:notebook:](http://en.wikipedia.org/wiki/Singleton_pattern) (is considered an anti-pattern! :no_entry:) +* [StaticFactory](StaticFactory) diff --git a/More/README.md b/More/README.md new file mode 100644 index 0000000..ac8709b --- /dev/null +++ b/More/README.md @@ -0,0 +1,4 @@ +# Others + +* [Delegation](Delegation) [:notebook:](http://en.wikipedia.org/wiki/Delegation_pattern) +* [ServiceLocator](ServiceLocator) [:notebook:](http://en.wikipedia.org/wiki/Service_locator_pattern) \ No newline at end of file diff --git a/README.md b/README.md index 56fd4df..4313611 100644 --- a/README.md +++ b/README.md @@ -10,46 +10,47 @@ I think the problem with patterns is that often people do know them but don't kn The patterns can be structured in roughly three different categories. Please click on the [:notebook:](http://en.wikipedia.org/wiki/Software_design_pattern) for a full explanation of the pattern on Wikipedia. -### Creational +### [Creational](Creational) -* [AbstractFactory](AbstractFactory) [:notebook:](http://en.wikipedia.org/wiki/Abstract_factory_pattern) -* [Builder](Builder) [:notebook:](http://en.wikipedia.org/wiki/Builder_pattern) -* [SimpleFactory](SimpleFactory) -* [FactoryMethod](FactoryMethod) [:notebook:](http://en.wikipedia.org/wiki/Factory_method_pattern) -* [StaticFactory](StaticFactory) -* [Prototype](Prototype) [:notebook:](http://en.wikipedia.org/wiki/Prototype_pattern) -* [Pool](Pool) [:notebook:](http://en.wikipedia.org/wiki/Object_pool_pattern) -* [Singleton](Singleton) [:notebook:](http://en.wikipedia.org/wiki/Singleton_pattern) (is considered an anti-pattern! :no_entry:) -* [Multiton](Multiton) (is considered an anti-pattern! :no_entry:) +* [AbstractFactory](Creational/AbstractFactory) [:notebook:](http://en.wikipedia.org/wiki/Abstract_factory_pattern) +* [Builder](Creational/Builder) [:notebook:](http://en.wikipedia.org/wiki/Builder_pattern) +* [SimpleFactory](Creational/SimpleFactory) +* [FactoryMethod](Creational/FactoryMethod) [:notebook:](http://en.wikipedia.org/wiki/Factory_method_pattern) +* [StaticFactory](Creational/StaticFactory) +* [Prototype](Creational/Prototype) [:notebook:](http://en.wikipedia.org/wiki/Prototype_pattern) +* [Pool](Creational/Pool) [:notebook:](http://en.wikipedia.org/wiki/Object_pool_pattern) +* [Singleton](Creational/Singleton) [:notebook:](http://en.wikipedia.org/wiki/Singleton_pattern) (is considered an anti-pattern! :no_entry:) +* [Multiton](Creational/Multiton) (is considered an anti-pattern! :no_entry:) -### Structural +### [Structural](Structural) -* [Adapter](Adapter) [:notebook:](http://en.wikipedia.org/wiki/Adapter_pattern) -* [Composite](Composite) [:notebook:](http://en.wikipedia.org/wiki/Composite_pattern) -* [Decorator](Decorator) [:notebook:](http://en.wikipedia.org/wiki/Decorator_pattern) -* [Facade](Facade) [:notebook:](http://en.wikipedia.org/wiki/Facade_pattern) -* [Proxy](Proxy) [:notebook:](http://en.wikipedia.org/wiki/Proxy_pattern) -* [Registry](Registry) [:notebook:](http://en.wikipedia.org/wiki/Service_locator_pattern) -* [FluentInterface](FluentInterface) [:notebook:](http://en.wikipedia.org/wiki/Fluent_interface) -* [DataMapper](DataMapper) [:notebook:](http://en.wikipedia.org/wiki/Data_mapper_pattern) -* [DependencyInjection](DependencyInjection) [:notebook:](http://en.wikipedia.org/wiki/Dependency_injection) +* [Adapter](Structural/Adapter) [:notebook:](http://en.wikipedia.org/wiki/Adapter_pattern) +* [Composite](Structural/Composite) [:notebook:](http://en.wikipedia.org/wiki/Composite_pattern) +* [DataMapper](Structural/DataMapper) [:notebook:](http://en.wikipedia.org/wiki/Data_mapper_pattern) +* [Decorator](Structural/Decorator) [:notebook:](http://en.wikipedia.org/wiki/Decorator_pattern) +* [DependencyInjection](Structural/DependencyInjection) [:notebook:](http://en.wikipedia.org/wiki/Dependency_injection) +* [Facade](Structural/Facade) [:notebook:](http://en.wikipedia.org/wiki/Facade_pattern) +* [FluentInterface](Structural/FluentInterface) [:notebook:](http://en.wikipedia.org/wiki/Fluent_interface) +* [Proxy](Structural/Proxy) [:notebook:](http://en.wikipedia.org/wiki/Proxy_pattern) +* [Registry](Structural/Registry) [:notebook:](http://en.wikipedia.org/wiki/Service_locator_pattern) -### Behavioral +### [Behavioral](Behavioral) -* [ChainOfResponsibilities](ChainOfResponsibilities) [:notebook:](http://en.wikipedia.org/wiki/Chain_of_responsibility_pattern) -* [Command](Command) [:notebook:](http://en.wikipedia.org/wiki/Command_pattern) -* [Iterator](Iterator) [:notebook:](http://en.wikipedia.org/wiki/Iterator_pattern) -* [Mediator](Mediator) [:notebook:](http://en.wikipedia.org/wiki/Mediator_pattern) -* [NullObject](NullObject) [:notebook:](http://en.wikipedia.org/wiki/Null_Object_pattern) -* [Observer](Observer) [:notebook:](http://en.wikipedia.org/wiki/Observer_pattern) -* [Specification](Specification) [:notebook:](http://en.wikipedia.org/wiki/Specification_pattern) -* [State](State) [:notebook:](http://en.wikipedia.org/wiki/State_pattern) -* [Strategy](Strategy) [:notebook:](http://en.wikipedia.org/wiki/Strategy_pattern) -* [TemplateMethod](TemplateMethod) [:notebook:](http://en.wikipedia.org/wiki/Template_method_pattern) -* [Visitor](Visitor) [:notebook:](http://en.wikipedia.org/wiki/Visitor_pattern) +* [ChainOfResponsibilities](Behavioral/ChainOfResponsibilities) [:notebook:](http://en.wikipedia.org/wiki/Chain_of_responsibility_pattern) +* [Command](Behavioral/Command) [:notebook:](http://en.wikipedia.org/wiki/Command_pattern) +* [Iterator](Behavioral/Iterator) [:notebook:](http://en.wikipedia.org/wiki/Iterator_pattern) +* [Mediator](Behavioral/Mediator) [:notebook:](http://en.wikipedia.org/wiki/Mediator_pattern) +* [NullObject](Behavioral/NullObject) [:notebook:](http://en.wikipedia.org/wiki/Null_Object_pattern) +* [Observer](Behavioral/Observer) [:notebook:](http://en.wikipedia.org/wiki/Observer_pattern) +* [Specification](Behavioral/Specification) [:notebook:](http://en.wikipedia.org/wiki/Specification_pattern) +* [State](Behavioral/State) [:notebook:](http://en.wikipedia.org/wiki/State_pattern) +* [Strategy](Behavioral/Strategy) [:notebook:](http://en.wikipedia.org/wiki/Strategy_pattern) +* [TemplateMethod](Behavioral/TemplateMethod) [:notebook:](http://en.wikipedia.org/wiki/Template_method_pattern) +* [Visitor](Behavioral/Visitor) [:notebook:](http://en.wikipedia.org/wiki/Visitor_pattern) -### More -* [Delegation](Delegation) [:notebook:](http://en.wikipedia.org/wiki/Delegation_pattern) +### [More](More) +* [Delegation](More/Delegation) [:notebook:](http://en.wikipedia.org/wiki/Delegation_pattern) +* [ServiceLocator](More/ServiceLocator) [:notebook:](http://en.wikipedia.org/wiki/Service_locator_pattern) ## Contribute diff --git a/Structural/README.md b/Structural/README.md new file mode 100644 index 0000000..659d7e2 --- /dev/null +++ b/Structural/README.md @@ -0,0 +1,11 @@ +# Structural + +* [Adapter](Adapter) [:notebook:](http://en.wikipedia.org/wiki/Adapter_pattern) +* [Composite](Composite) [:notebook:](http://en.wikipedia.org/wiki/Composite_pattern) +* [DataMapper](DataMapper) [:notebook:](http://en.wikipedia.org/wiki/Data_mapper_pattern) +* [Decorator](Decorator) [:notebook:](http://en.wikipedia.org/wiki/Decorator_pattern) +* [DependencyInjection](DependencyInjection) [:notebook:](http://en.wikipedia.org/wiki/Dependency_injection) +* [Facade](Facade) [:notebook:](http://en.wikipedia.org/wiki/Facade_pattern) +* [FluentInterface](FluentInterface) [:notebook:](http://en.wikipedia.org/wiki/Fluent_interface) +* [Proxy](Proxy) [:notebook:](http://en.wikipedia.org/wiki/Proxy_pattern) +* [Registry](Registry) [:notebook:](http://en.wikipedia.org/wiki/Service_locator_pattern) From f1af89ecc6c84eee58712bc294af5634917dbd00 Mon Sep 17 00:00:00 2001 From: Antonio Spinelli Date: Wed, 16 Apr 2014 14:54:31 -0300 Subject: [PATCH 08/17] add simple explanation about behavioral --- Behavioral/README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Behavioral/README.md b/Behavioral/README.md index 470d3fd..d9c264e 100644 --- a/Behavioral/README.md +++ b/Behavioral/README.md @@ -1,5 +1,10 @@ # Behavioral +In software engineering, behavioral design patterns are design patterns that +identify common communication patterns between objects and realize these +patterns. By doing so, these patterns increase flexibility in carrying out this +communication. + * [ChainOfResponsibilities](ChainOfResponsibilities) [:notebook:](http://en.wikipedia.org/wiki/Chain_of_responsibility_pattern) * [Command](Command) [:notebook:](http://en.wikipedia.org/wiki/Command_pattern) * [Iterator](Iterator) [:notebook:](http://en.wikipedia.org/wiki/Iterator_pattern) From f3fe7e4ed3229f1f19774a0546c57bdacb42691c Mon Sep 17 00:00:00 2001 From: Antonio Spinelli Date: Wed, 16 Apr 2014 14:55:16 -0300 Subject: [PATCH 09/17] add simple explanation about structural --- Structural/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Structural/README.md b/Structural/README.md index 659d7e2..ad0a414 100644 --- a/Structural/README.md +++ b/Structural/README.md @@ -1,5 +1,9 @@ # Structural +In Software Engineering, Structural Design Patterns are Design Patterns that +ease the design by identifying a simple way to realize relationships between +entities. + * [Adapter](Adapter) [:notebook:](http://en.wikipedia.org/wiki/Adapter_pattern) * [Composite](Composite) [:notebook:](http://en.wikipedia.org/wiki/Composite_pattern) * [DataMapper](DataMapper) [:notebook:](http://en.wikipedia.org/wiki/Data_mapper_pattern) From 6f65ffa58ed3bdf5d772273f0d20088e565dd322 Mon Sep 17 00:00:00 2001 From: Antonio Spinelli Date: Wed, 16 Apr 2014 14:56:25 -0300 Subject: [PATCH 10/17] add simple explanation about creational --- Creational/README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Creational/README.md b/Creational/README.md index d31a692..a201713 100644 --- a/Creational/README.md +++ b/Creational/README.md @@ -1,5 +1,11 @@ # Creational +In software engineering, creational design patterns are design patterns that +deal with object creation mechanisms, trying to create objects in a manner +suitable to the situation. The basic form of object creation could result in +design problems or added complexity to the design. Creational design patterns +solve this problem by somehow controlling this object creation. + * [AbstractFactory](AbstractFactory) [:notebook:](http://en.wikipedia.org/wiki/Abstract_factory_pattern) * [Builder](Builder) [:notebook:](http://en.wikipedia.org/wiki/Builder_pattern) * [FactoryMethod](FactoryMethod) [:notebook:](http://en.wikipedia.org/wiki/Factory_method_pattern) From da35c96b90eb04b2aaf3623ec8b19c1c0c82dfad Mon Sep 17 00:00:00 2001 From: Antonio Spinelli Date: Wed, 16 Apr 2014 15:05:03 -0300 Subject: [PATCH 11/17] fix typo --- More/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/More/README.md b/More/README.md index ac8709b..bea0cf5 100644 --- a/More/README.md +++ b/More/README.md @@ -1,4 +1,4 @@ -# Others +# More * [Delegation](Delegation) [:notebook:](http://en.wikipedia.org/wiki/Delegation_pattern) * [ServiceLocator](ServiceLocator) [:notebook:](http://en.wikipedia.org/wiki/Service_locator_pattern) \ No newline at end of file From fc3b6a1608250e34d5edcd2f47c25d0862d7ff0e Mon Sep 17 00:00:00 2001 From: Antonio Spinelli Date: Wed, 16 Apr 2014 17:59:03 -0300 Subject: [PATCH 12/17] cs fix --- Behavioral/ChainOfResponsibilities/ChainTest.php | 9 ++++++--- Behavioral/Iterator/BookList.php | 2 +- Behavioral/Iterator/BookListIterator.php | 2 +- Behavioral/Iterator/BookListReverseIterator.php | 2 +- Behavioral/Iterator/IteratorTest.php | 2 +- Behavioral/Observer/ObserverTest.php | 7 +++---- .../Specification/AbstractSpecification.php | 16 ++++++++-------- Behavioral/Specification/Not.php | 2 +- Behavioral/Specification/Plus.php | 9 ++++----- Behavioral/Specification/PriceSpecification.php | 8 ++++---- .../Specification/SpecificationInterface.php | 12 +++++------- Behavioral/Strategy/ObjectCollection.php | 6 +++--- Behavioral/TemplateMethod/JourneyTest.php | 7 +++---- Behavioral/Visitor/VisitorTest.php | 3 +-- Creational/Pool/Pool.php | 3 +-- Creational/Pool/PoolTest.php | 3 --- Creational/Pool/Processor.php | 1 - Creational/Pool/Worker.php | 1 - Creational/SimpleFactory/SimpleFactoryTest.php | 3 +-- Structural/Adapter/AdapterTest.php | 2 +- Structural/Composite/CompositeTest.php | 4 +++- Structural/DataMapper/DataMapperTest.php | 7 ++++++- Structural/Decorator/DecoratorTest.php | 7 +++++-- Structural/DependencyInjection/ArrayConfig.php | 7 ++++--- Structural/DependencyInjection/Parameters.php | 4 ++-- 25 files changed, 65 insertions(+), 64 deletions(-) diff --git a/Behavioral/ChainOfResponsibilities/ChainTest.php b/Behavioral/ChainOfResponsibilities/ChainTest.php index 23e5625..9fe7f30 100644 --- a/Behavioral/ChainOfResponsibilities/ChainTest.php +++ b/Behavioral/ChainOfResponsibilities/ChainTest.php @@ -45,7 +45,8 @@ class ChainTest extends \PHPUnit_Framework_TestCase $this->assertObjectHasAttribute('response', $request); $this->assertEquals('baz', $request->response); // despite both handle owns the 'bar' key, the FastStorage is responding first - $this->assertEquals('DesignPatterns\Behavioral\ChainOfResponsibilities\Responsible\FastStorage', $request->forDebugOnly); + $className = 'DesignPatterns\Behavioral\ChainOfResponsibilities\Responsible\FastStorage'; + $this->assertEquals($className, $request->forDebugOnly); } /** @@ -60,7 +61,8 @@ class ChainTest extends \PHPUnit_Framework_TestCase $this->assertObjectHasAttribute('response', $request); $this->assertEquals('bar', $request->response); // FastStorage has no 'foo' key, the SlowStorage is responding - $this->assertEquals('DesignPatterns\Behavioral\ChainOfResponsibilities\Responsible\SlowStorage', $request->forDebugOnly); + $className = 'DesignPatterns\Behavioral\ChainOfResponsibilities\Responsible\SlowStorage'; + $this->assertEquals($className, $request->forDebugOnly); } /** @@ -73,6 +75,7 @@ class ChainTest extends \PHPUnit_Framework_TestCase $this->assertFalse($ret); // the last responsible : - $this->assertEquals('DesignPatterns\Behavioral\ChainOfResponsibilities\Responsible\SlowStorage', $request->forDebugOnly); + $className = 'DesignPatterns\Behavioral\ChainOfResponsibilities\Responsible\SlowStorage'; + $this->assertEquals($className, $request->forDebugOnly); } } diff --git a/Behavioral/Iterator/BookList.php b/Behavioral/Iterator/BookList.php index eb9a8be..0dda925 100644 --- a/Behavioral/Iterator/BookList.php +++ b/Behavioral/Iterator/BookList.php @@ -13,7 +13,7 @@ class BookList implements \Countable return $this->books[$bookNumberToGet]; } - return NULL; + return null; } public function addBook(Book $book) diff --git a/Behavioral/Iterator/BookListIterator.php b/Behavioral/Iterator/BookListIterator.php index d0992c6..bc15ffb 100644 --- a/Behavioral/Iterator/BookListIterator.php +++ b/Behavioral/Iterator/BookListIterator.php @@ -74,4 +74,4 @@ class BookListIterator implements \Iterator { $this->currentBook = 0; } -} \ No newline at end of file +} diff --git a/Behavioral/Iterator/BookListReverseIterator.php b/Behavioral/Iterator/BookListReverseIterator.php index 2e38f63..973bd0b 100644 --- a/Behavioral/Iterator/BookListReverseIterator.php +++ b/Behavioral/Iterator/BookListReverseIterator.php @@ -20,4 +20,4 @@ class BookListReverseIterator extends BookListIterator { return 0 <= $this->currentBook; } -} \ No newline at end of file +} diff --git a/Behavioral/Iterator/IteratorTest.php b/Behavioral/Iterator/IteratorTest.php index e9e553d..83cdb0f 100644 --- a/Behavioral/Iterator/IteratorTest.php +++ b/Behavioral/Iterator/IteratorTest.php @@ -63,4 +63,4 @@ class IteratorTest extends \PHPUnit_Framework_TestCase $iterator->next(); } } -} \ No newline at end of file +} diff --git a/Behavioral/Observer/ObserverTest.php b/Behavioral/Observer/ObserverTest.php index 86a3e9b..0ecd9c9 100644 --- a/Behavioral/Observer/ObserverTest.php +++ b/Behavioral/Observer/ObserverTest.php @@ -53,10 +53,9 @@ class ObserverTest extends \PHPUnit_Framework_TestCase $subject->attach($observer); $observer->expects($this->once()) - ->method('update') - ->with($subject); + ->method('update') + ->with($subject); $subject->notify(); } - -} \ No newline at end of file +} diff --git a/Behavioral/Specification/AbstractSpecification.php b/Behavioral/Specification/AbstractSpecification.php index 8ece67b..f297539 100644 --- a/Behavioral/Specification/AbstractSpecification.php +++ b/Behavioral/Specification/AbstractSpecification.php @@ -8,18 +8,18 @@ abstract class AbstractSpecification implements SpecificationInterface { /** * Checks if given item meets all criteria - * + * * @param Item $item - * + * * @return bool */ abstract public function isSatisfiedBy(Item $item); /** * Creates a new logical AND specification - * + * * @param SpecificationInterface $spec - * + * * @return SpecificationInterface */ public function plus(SpecificationInterface $spec) @@ -29,9 +29,9 @@ abstract class AbstractSpecification implements SpecificationInterface /** * Creates a new logical OR composite specification - * + * * @param SpecificationInterface $spec - * + * * @return SpecificationInterface */ public function either(SpecificationInterface $spec) @@ -41,11 +41,11 @@ abstract class AbstractSpecification implements SpecificationInterface /** * Creates a new logical NOT specification - * + * * @return SpecificationInterface */ public function not() { return new Not($this); } -} \ No newline at end of file +} diff --git a/Behavioral/Specification/Not.php b/Behavioral/Specification/Not.php index ea06f53..f46999d 100644 --- a/Behavioral/Specification/Not.php +++ b/Behavioral/Specification/Not.php @@ -31,4 +31,4 @@ class Not extends AbstractSpecification { return !$this->spec->isSatisfiedBy($item); } -} \ No newline at end of file +} diff --git a/Behavioral/Specification/Plus.php b/Behavioral/Specification/Plus.php index 9762c15..c4ad546 100644 --- a/Behavioral/Specification/Plus.php +++ b/Behavioral/Specification/Plus.php @@ -12,10 +12,9 @@ class Plus extends AbstractSpecification /** * Creation of a locical AND of two specifications - * + * * @param SpecificationInterface $left * @param SpecificationInterface $right - */ public function __construct(SpecificationInterface $left, SpecificationInterface $right) { @@ -25,13 +24,13 @@ class Plus extends AbstractSpecification /** * Checks if the composite AND of specifications passes - * + * * @param Item $item - * + * * @return bool */ public function isSatisfiedBy(Item $item) { return $this->left->isSatisfiedBy($item) && $this->right->isSatisfiedBy($item); } -} \ No newline at end of file +} diff --git a/Behavioral/Specification/PriceSpecification.php b/Behavioral/Specification/PriceSpecification.php index fa74d2a..747efdf 100644 --- a/Behavioral/Specification/PriceSpecification.php +++ b/Behavioral/Specification/PriceSpecification.php @@ -31,17 +31,17 @@ class PriceSpecification extends AbstractSpecification /** * Checks if Item price falls between bounds - * + * * @param Item $item - * + * * @return bool */ public function isSatisfiedBy(Item $item) { - if ( !empty($this->maxPrice) && $item->getPrice() > $this->maxPrice) { + if (!empty($this->maxPrice) && $item->getPrice() > $this->maxPrice) { return false; } - if ( !empty($this->minPrice) && $item->getPrice() < $this->minPrice) { + if (!empty($this->minPrice) && $item->getPrice() < $this->minPrice) { return false; } diff --git a/Behavioral/Specification/SpecificationInterface.php b/Behavioral/Specification/SpecificationInterface.php index a00712f..e4e15a2 100644 --- a/Behavioral/Specification/SpecificationInterface.php +++ b/Behavioral/Specification/SpecificationInterface.php @@ -8,26 +8,24 @@ interface SpecificationInterface { /** * A boolean evaluation indicating if the object meets the specification - * + * * @param Item $item - * + * * @return bool */ public function isSatisfiedBy(Item $item); /** * Creates a logical AND specification - * + * * @param SpecificationInterface $spec - */ public function plus(SpecificationInterface $spec); /** * Creates a logical OR specification - * + * * @param SpecificationInterface $spec - */ public function either(SpecificationInterface $spec); @@ -35,4 +33,4 @@ interface SpecificationInterface * Creates a logical not specification */ public function not(); -} \ No newline at end of file +} diff --git a/Behavioral/Strategy/ObjectCollection.php b/Behavioral/Strategy/ObjectCollection.php index 1006f8f..1b4fa88 100644 --- a/Behavioral/Strategy/ObjectCollection.php +++ b/Behavioral/Strategy/ObjectCollection.php @@ -30,10 +30,10 @@ class ObjectCollection */ public function sort() { - if (!$this->comparator){ - throw new \LogicException("Comparator is not set"); + if (!$this->comparator) { + throw new \LogicException("Comparator is not set"); } - + $callback = array($this->comparator, 'compare'); uasort($this->elements, $callback); diff --git a/Behavioral/TemplateMethod/JourneyTest.php b/Behavioral/TemplateMethod/JourneyTest.php index 34b576b..b99f2aa 100644 --- a/Behavioral/TemplateMethod/JourneyTest.php +++ b/Behavioral/TemplateMethod/JourneyTest.php @@ -31,8 +31,8 @@ class JourneyTest extends \PHPUnit_Framework_TestCase { $journey = $this->getMockForAbstractClass('DesignPatterns\Behavioral\TemplateMethod\Journey'); $journey->expects($this->once()) - ->method('enjoyVacation') - ->will($this->returnCallback(array($this, 'mockUpVacation'))); + ->method('enjoyVacation') + ->will($this->returnCallback(array($this, 'mockUpVacation'))); $this->expectOutputRegex('#Las Vegas#'); $journey->takeATrip(); } @@ -41,5 +41,4 @@ class JourneyTest extends \PHPUnit_Framework_TestCase { echo "Fear and loathing in Las Vegas\n"; } - -} \ No newline at end of file +} diff --git a/Behavioral/Visitor/VisitorTest.php b/Behavioral/Visitor/VisitorTest.php index fd21dea..104c770 100644 --- a/Behavioral/Visitor/VisitorTest.php +++ b/Behavioral/Visitor/VisitorTest.php @@ -43,5 +43,4 @@ class VisitorTest extends \PHPUnit_Framework_TestCase $mock = $this->getMockForAbstractClass('DesignPatterns\Behavioral\Visitor\Role'); $mock->accept($this->visitor); } - -} \ No newline at end of file +} diff --git a/Creational/Pool/Pool.php b/Creational/Pool/Pool.php index dcd1611..e3a809b 100644 --- a/Creational/Pool/Pool.php +++ b/Creational/Pool/Pool.php @@ -7,7 +7,7 @@ class Pool private $instances = array(); private $class; - + public function __construct($class) { $this->class = $class; @@ -26,5 +26,4 @@ class Pool { $this->instances[] = $instance; } - } diff --git a/Creational/Pool/PoolTest.php b/Creational/Pool/PoolTest.php index f52d2f9..e0b062d 100644 --- a/Creational/Pool/PoolTest.php +++ b/Creational/Pool/PoolTest.php @@ -2,8 +2,6 @@ namespace DesignPatterns\Creational\Pool; -use DesignPatterns\Creational\Pool\Pool; - class TestWorker { @@ -27,4 +25,3 @@ class PoolTest extends \PHPUnit_Framework_TestCase $this->assertEquals(1, $pool->get()->id); } } - diff --git a/Creational/Pool/Processor.php b/Creational/Pool/Processor.php index 47523b0..0bb5e67 100644 --- a/Creational/Pool/Processor.php +++ b/Creational/Pool/Processor.php @@ -49,5 +49,4 @@ class Processor { return array_pop($this->waitingQueue); } - } diff --git a/Creational/Pool/Worker.php b/Creational/Pool/Worker.php index a176372..acdc1ba 100644 --- a/Creational/Pool/Worker.php +++ b/Creational/Pool/Worker.php @@ -17,5 +17,4 @@ class Worker // and when it's done, execute callback call_user_func($callback, $this); } - } diff --git a/Creational/SimpleFactory/SimpleFactoryTest.php b/Creational/SimpleFactory/SimpleFactoryTest.php index 0c2c470..1233609 100644 --- a/Creational/SimpleFactory/SimpleFactoryTest.php +++ b/Creational/SimpleFactory/SimpleFactoryTest.php @@ -41,5 +41,4 @@ class SimpleFactoryTest extends \PHPUnit_Framework_TestCase { $this->factory->createVehicle('car'); } - -} \ No newline at end of file +} diff --git a/Structural/Adapter/AdapterTest.php b/Structural/Adapter/AdapterTest.php index 55cc5e2..0d86739 100644 --- a/Structural/Adapter/AdapterTest.php +++ b/Structural/Adapter/AdapterTest.php @@ -33,7 +33,7 @@ class AdapterTest extends \PHPUnit_Framework_TestCase * * @dataProvider getBook */ - public function test_I_am_an_old_Client(PaperBookInterface $book) + public function testIAmAnOldClient(PaperBookInterface $book) { $book->open(); $book->turnPage(); diff --git a/Structural/Composite/CompositeTest.php b/Structural/Composite/CompositeTest.php index d6472a3..50b3131 100644 --- a/Structural/Composite/CompositeTest.php +++ b/Structural/Composite/CompositeTest.php @@ -29,6 +29,8 @@ class CompositeTest extends \PHPUnit_Framework_TestCase */ public function testFormImplementsFormEelement() { - $this->assertTrue(is_subclass_of('DesignPatterns\Structural\Composite\Form', 'DesignPatterns\Structural\Composite\FormElement')); + $className = 'DesignPatterns\Structural\Composite\Form'; + $abstractName = 'DesignPatterns\Structural\Composite\FormElement'; + $this->assertTrue(is_subclass_of($className, $abstractName)); } } diff --git a/Structural/DataMapper/DataMapperTest.php b/Structural/DataMapper/DataMapperTest.php index e6b110e..b5f7c4c 100644 --- a/Structural/DataMapper/DataMapperTest.php +++ b/Structural/DataMapper/DataMapperTest.php @@ -65,7 +65,12 @@ class DataMapperTest extends \PHPUnit_Framework_TestCase */ public function testRestoreOne(User $existing) { - $rows = new \ArrayIterator(array(array('userid' => 1, 'username' => 'Odysseus', 'email' => 'Odysseus@ithaca.gr'))); + $row = array( + 'userid' => 1, + 'username' => 'Odysseus', + 'email' => 'Odysseus@ithaca.gr' + ); + $rows = new \ArrayIterator(array($row)); $this->dbal->expects($this->once()) ->method('find') ->with(1) diff --git a/Structural/Decorator/DecoratorTest.php b/Structural/Decorator/DecoratorTest.php index 9414524..31adc2f 100644 --- a/Structural/Decorator/DecoratorTest.php +++ b/Structural/Decorator/DecoratorTest.php @@ -30,7 +30,8 @@ class DecoratorTest extends \PHPUnit_Framework_TestCase // Wrap service with a JSON decorator for renderers $service = new Decorator\RenderInXml($this->service); // Our Renderer will now output XML instead of an array - $this->assertXmlStringEqualsXmlString('bar', $service->renderData()); + $xml = 'bar'; + $this->assertXmlStringEqualsXmlString($xml, $service->renderData()); } /** @@ -38,7 +39,9 @@ class DecoratorTest extends \PHPUnit_Framework_TestCase */ public function testDecoratorMustImplementsRenderer() { - $this->assertTrue(is_subclass_of('DesignPatterns\Structural\Decorator\Decorator', 'DesignPatterns\Structural\Decorator\RendererInterface')); + $className = 'DesignPatterns\Structural\Decorator\Decorator'; + $interfaceName = 'DesignPatterns\Structural\Decorator\RendererInterface'; + $this->assertTrue(is_subclass_of($className, $interfaceName)); } /** diff --git a/Structural/DependencyInjection/ArrayConfig.php b/Structural/DependencyInjection/ArrayConfig.php index 15a9462..91bca33 100644 --- a/Structural/DependencyInjection/ArrayConfig.php +++ b/Structural/DependencyInjection/ArrayConfig.php @@ -13,10 +13,11 @@ class ArrayConfig extends AbstractConfig implements Parameters * Get parameter * * @param string|int $key - * + * @param null $default * @return mixed */ - public function get($key, $default = null) { + public function get($key, $default = null) + { if (isset($this->storage[$key])) { return $this->storage[$key]; } @@ -27,7 +28,7 @@ class ArrayConfig extends AbstractConfig implements Parameters * Set parameter * * @param string|int $key - * @param mixed $value + * @param mixed $value */ public function set($key, $value) { diff --git a/Structural/DependencyInjection/Parameters.php b/Structural/DependencyInjection/Parameters.php index 679df3a..dabe895 100644 --- a/Structural/DependencyInjection/Parameters.php +++ b/Structural/DependencyInjection/Parameters.php @@ -5,13 +5,13 @@ namespace DesignPatterns\Structural\DependencyInjection; /** * Parameters interface */ -interface Parameters +interface Parameters { /** * Get parameter * * @param string|int $key - * + * * @return mixed */ public function get($key); From c1ca6b42e2b6bb2f463c0f3d8fb4b94995ce4458 Mon Sep 17 00:00:00 2001 From: Antonio Spinelli Date: Wed, 16 Apr 2014 18:12:52 -0300 Subject: [PATCH 13/17] it was created the More namespace and append its patterns --- More/Delegation/{Test => }/DelegationTest.php | 4 +- More/Delegation/JuniorDeveloper.php | 2 +- More/Delegation/TeamLead.php | 2 +- More/Delegation/Usage.php | 2 +- More/ServiceLocator/DatabaseService.php | 5 +- .../DatabaseServiceInterface.php | 5 +- More/ServiceLocator/LogService.php | 5 +- More/ServiceLocator/LogServiceInterface.php | 5 +- More/ServiceLocator/ServiceLocator.php | 25 +++--- .../ServiceLocatorInterface.php | 6 +- More/ServiceLocator/ServiceLocatorTest.php | 85 +++++++++++++++++++ .../Test/ServiceLocatorTest.php | 79 ----------------- 12 files changed, 114 insertions(+), 111 deletions(-) rename More/Delegation/{Test => }/DelegationTest.php (82%) create mode 100644 More/ServiceLocator/ServiceLocatorTest.php delete mode 100644 More/ServiceLocator/Test/ServiceLocatorTest.php diff --git a/More/Delegation/Test/DelegationTest.php b/More/Delegation/DelegationTest.php similarity index 82% rename from More/Delegation/Test/DelegationTest.php rename to More/Delegation/DelegationTest.php index f9265a7..5823f85 100644 --- a/More/Delegation/Test/DelegationTest.php +++ b/More/Delegation/DelegationTest.php @@ -1,8 +1,8 @@ services = array(); + $this->services = array(); $this->instantiated = array(); - $this->shared = array(); + $this->shared = array(); } /** * Registers a service with specific interface. * - * @param string $interface + * @param string $interface * @param string|object $service - * @param bool $share + * @param bool $share */ public function add($interface, $service, $share = true) { @@ -47,11 +47,11 @@ class ServiceLocator implements ServiceLocatorInterface * in the future even if you will change the service implementation. */ - if(is_object($service) && $share) + if (is_object($service) && $share) { $this->instantiated[$interface] = $service; - + } $this->services[$interface] = (is_object($service) ? get_class($service) : $service); - $this->shared[$interface] = $share; + $this->shared[$interface] = $share; } /** @@ -76,8 +76,9 @@ class ServiceLocator implements ServiceLocatorInterface public function get($interface) { // Retrieves the instance if it exists and it is shared - if(isset($this->instantiated[$interface]) && $this->shared[$interface]) + if (isset($this->instantiated[$interface]) && $this->shared[$interface]) { return $this->instantiated[$interface]; + } // otherwise gets the service registered. $service = $this->services[$interface]; @@ -97,9 +98,9 @@ class ServiceLocator implements ServiceLocatorInterface $object = new $service(); // and saves it if the service must be shared. - if($this->shared[$interface]) + if ($this->shared[$interface]) { $this->instantiated[$interface] = $object; - + } return $object; } -} \ No newline at end of file +} diff --git a/More/ServiceLocator/ServiceLocatorInterface.php b/More/ServiceLocator/ServiceLocatorInterface.php index ffd4006..3738624 100644 --- a/More/ServiceLocator/ServiceLocatorInterface.php +++ b/More/ServiceLocator/ServiceLocatorInterface.php @@ -1,8 +1,8 @@ serviceLocator = new ServiceLocator(); + + $this->logService = new LogService(); + $this->databaseService = new DatabaseService(); + } + + public function testHasServices() + { + $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')); + + $this->assertFalse($this->serviceLocator->has('DesignPatterns\More\ServiceLocator\FakeServiceInterface')); + } + + 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')); + } + + 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')); + } + + 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')); + } +} diff --git a/More/ServiceLocator/Test/ServiceLocatorTest.php b/More/ServiceLocator/Test/ServiceLocatorTest.php deleted file mode 100644 index 8fc0670..0000000 --- a/More/ServiceLocator/Test/ServiceLocatorTest.php +++ /dev/null @@ -1,79 +0,0 @@ -serviceLocator = new ServiceLocator(); - - $this->logService = new LogService(); - $this->databaseService = new DatabaseService(); - } - - public function testHasServices() - { - $this->serviceLocator->add('DesignPatterns\ServiceLocator\LogServiceInterface', $this->logService); - $this->serviceLocator->add('DesignPatterns\ServiceLocator\DatabaseServiceInterface', $this->databaseService); - - $this->assertTrue($this->serviceLocator->has('DesignPatterns\ServiceLocator\LogServiceInterface')); - $this->assertTrue($this->serviceLocator->has('DesignPatterns\ServiceLocator\DatabaseServiceInterface')); - - $this->assertFalse($this->serviceLocator->has('DesignPatterns\ServiceLocator\FakeServiceInterface')); - } - - public function testServicesWithObject() - { - $this->serviceLocator->add('DesignPatterns\ServiceLocator\LogServiceInterface', $this->logService); - $this->serviceLocator->add('DesignPatterns\ServiceLocator\DatabaseServiceInterface', $this->databaseService); - - $this->assertSame($this->logService, $this->serviceLocator->get('DesignPatterns\ServiceLocator\LogServiceInterface')); - $this->assertSame($this->databaseService, $this->serviceLocator->get('DesignPatterns\ServiceLocator\DatabaseServiceInterface')); - } - - public function testServicesWithClass() - { - $this->serviceLocator->add('DesignPatterns\ServiceLocator\LogServiceInterface', get_class($this->logService)); - $this->serviceLocator->add('DesignPatterns\ServiceLocator\DatabaseServiceInterface', get_class($this->databaseService)); - - $this->assertNotSame($this->logService, $this->serviceLocator->get('DesignPatterns\ServiceLocator\LogServiceInterface')); - $this->assertInstanceOf('DesignPatterns\ServiceLocator\LogServiceInterface', $this->serviceLocator->get('DesignPatterns\ServiceLocator\LogServiceInterface')); - - $this->assertNotSame($this->databaseService, $this->serviceLocator->get('DesignPatterns\ServiceLocator\DatabaseServiceInterface')); - $this->assertInstanceOf('DesignPatterns\ServiceLocator\DatabaseServiceInterface', $this->serviceLocator->get('DesignPatterns\ServiceLocator\DatabaseServiceInterface')); - } - - public function testServicesNotShared() - { - $this->serviceLocator->add('DesignPatterns\ServiceLocator\LogServiceInterface', $this->logService, false); - $this->serviceLocator->add('DesignPatterns\ServiceLocator\DatabaseServiceInterface', $this->databaseService, false); - - $this->assertNotSame($this->logService, $this->serviceLocator->get('DesignPatterns\ServiceLocator\LogServiceInterface')); - $this->assertInstanceOf('DesignPatterns\ServiceLocator\LogServiceInterface', $this->serviceLocator->get('DesignPatterns\ServiceLocator\LogServiceInterface')); - - $this->assertNotSame($this->databaseService, $this->serviceLocator->get('DesignPatterns\ServiceLocator\DatabaseServiceInterface')); - $this->assertInstanceOf('DesignPatterns\ServiceLocator\DatabaseServiceInterface', $this->serviceLocator->get('DesignPatterns\ServiceLocator\DatabaseServiceInterface')); - } -} - \ No newline at end of file From 9beb7d9a58bc687ec5063096a58c7da2552f8020 Mon Sep 17 00:00:00 2001 From: Antonio Spinelli Date: Wed, 16 Apr 2014 18:21:18 -0300 Subject: [PATCH 14/17] fix testsuite configuration --- phpunit.xml.dist | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 391c078..0f03427 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -3,11 +3,15 @@ - ./Behavioral/*/*Test.php - ./Creational/*/*/Test.php - ./More/*/*/Test.php - ./Structural/*/*/Test.php + Behavioral + Creational + More + Structural - + + + ./vendor + + From 14a9dfe7cfef032b91292a2437ec8d628efb3559 Mon Sep 17 00:00:00 2001 From: Antonio Spinelli Date: Fri, 2 May 2014 12:33:44 -0300 Subject: [PATCH 15/17] merge from master --- Behavioral/Memento/Caretaker.php | 33 +++++++++++ Behavioral/Memento/Memento.php | 25 ++++++++ Behavioral/Memento/MementoTest.php | 67 ++++++++++++++++++++++ Behavioral/Memento/Originator.php | 35 +++++++++++ Behavioral/Memento/README.md | 18 ++++++ More/ServiceLocator/ServiceLocatorTest.php | 15 ++--- README.md | 14 +++-- Structural/Bridge/Assemble.php | 12 ++++ Structural/Bridge/BridgeTest.php | 21 +++++++ Structural/Bridge/Car.php | 22 +++++++ Structural/Bridge/Motorcycle.php | 22 +++++++ Structural/Bridge/Produce.php | 15 +++++ Structural/Bridge/README.md | 7 +++ Structural/Bridge/Vehicle.php | 23 ++++++++ Structural/Bridge/Workshop.php | 12 ++++ Structural/README.md | 1 + 16 files changed, 325 insertions(+), 17 deletions(-) create mode 100644 Behavioral/Memento/Caretaker.php create mode 100644 Behavioral/Memento/Memento.php create mode 100644 Behavioral/Memento/MementoTest.php create mode 100644 Behavioral/Memento/Originator.php create mode 100644 Behavioral/Memento/README.md create mode 100644 Structural/Bridge/Assemble.php create mode 100644 Structural/Bridge/BridgeTest.php create mode 100644 Structural/Bridge/Car.php create mode 100644 Structural/Bridge/Motorcycle.php create mode 100644 Structural/Bridge/Produce.php create mode 100644 Structural/Bridge/README.md create mode 100644 Structural/Bridge/Vehicle.php create mode 100644 Structural/Bridge/Workshop.php diff --git a/Behavioral/Memento/Caretaker.php b/Behavioral/Memento/Caretaker.php new file mode 100644 index 0000000..340bb97 --- /dev/null +++ b/Behavioral/Memento/Caretaker.php @@ -0,0 +1,33 @@ +setState("State1"); + //Setting state to State2 + $originator->setState("State2"); + //Saving State2 to Memento + $savedStates[] = $originator->saveToMemento(); + //Setting state to State3 + $originator->setState("State3"); + + // We can request multiple mementos, and choose which one to roll back to. + // Saving State3 to Memento + $savedStates[] = $originator->saveToMemento(); + //Setting state to State4 + $originator->setState("State4"); + + $originator->restoreFromMemento($savedStates[1]); + //State after restoring from Memento: State3 + } +} diff --git a/Behavioral/Memento/Memento.php b/Behavioral/Memento/Memento.php new file mode 100644 index 0000000..4dd2fc8 --- /dev/null +++ b/Behavioral/Memento/Memento.php @@ -0,0 +1,25 @@ +state = $stateToSave; + } + + /** + * @return mixed + */ + public function getState() + { + return $this->state; + } +} diff --git a/Behavioral/Memento/MementoTest.php b/Behavioral/Memento/MementoTest.php new file mode 100644 index 0000000..4d25d4d --- /dev/null +++ b/Behavioral/Memento/MementoTest.php @@ -0,0 +1,67 @@ +setState("State1"); + + $this->assertAttributeEquals("State1", "state", $originator); + + $originator->setState("State2"); + + $this->assertAttributeEquals("State2", "state", $originator); + + $savedState = $originator->saveToMemento(); + + $this->assertAttributeEquals("State2", "state", $savedState); + + $originator->setState("State3"); + + $this->assertAttributeEquals("State3", "state", $originator); + + $originator->restoreFromMemento($savedState); + + $this->assertAttributeEquals("State2", "state", $originator); + } + + public function testObjectState() + { + $originator = new Originator(); + + $foo = new \stdClass(); + $foo->data = "foo"; + + $originator->setState($foo); + + $this->assertAttributeEquals($foo, "state", $originator); + + $savedState = $originator->saveToMemento(); + + $this->assertAttributeEquals($foo, "state", $savedState); + + $bar = new \stdClass(); + $bar->data = "bar"; + + $originator->setState($bar); + + $this->assertAttributeEquals($bar, "state", $originator); + + $originator->restoreFromMemento($savedState); + + $this->assertAttributeEquals($foo, "state", $originator); + + $foo->data = null; + + $this->assertAttributeNotEquals($foo, "state", $savedState); + + $this->assertAttributeNotEquals($foo, "state", $originator); + } +} diff --git a/Behavioral/Memento/Originator.php b/Behavioral/Memento/Originator.php new file mode 100644 index 0000000..fec4e45 --- /dev/null +++ b/Behavioral/Memento/Originator.php @@ -0,0 +1,35 @@ +state = $state; + } + + /** + * @return Memento + */ + public function saveToMemento() + { + $state = is_object($this->state) ? clone $this->state : $this->state; + + return new Memento($state); + } + + public function restoreFromMemento(Memento $memento) + { + $this->state = $memento->getState(); + } +} diff --git a/Behavioral/Memento/README.md b/Behavioral/Memento/README.md new file mode 100644 index 0000000..83ca2c0 --- /dev/null +++ b/Behavioral/Memento/README.md @@ -0,0 +1,18 @@ +# Memento + +## Purpose + +Provide the ability to restore an object to its previous state (undo via rollback). + +The memento pattern is implemented with three objects: the originator, a caretaker and a memento. +The originator is some object that has an internal state. +The caretaker is going to do something to the originator, but wants to be able to undo the change. +The caretaker first asks the originator for a memento object. Then it does whatever operation (or sequence of operations) it was going to do. +To roll back to the state before the operations, it returns the memento object to the originator. +The memento object itself is an opaque object (one which the caretaker cannot, or should not, change). +When using this pattern, care should be taken if the originator may change other objects or resources - the memento pattern operates on a single object. + +## Examples + +* The seed of a pseudorandom number generator +* The state in a finite state machine diff --git a/More/ServiceLocator/ServiceLocatorTest.php b/More/ServiceLocator/ServiceLocatorTest.php index e50a436..5e20cc7 100644 --- a/More/ServiceLocator/ServiceLocatorTest.php +++ b/More/ServiceLocator/ServiceLocatorTest.php @@ -26,22 +26,15 @@ class ServiceLocatorTest extends TestCase public function setUp() { - $this->serviceLocator = new ServiceLocator(); - - $this->logService = new LogService(); + $this->serviceLocator = new ServiceLocator(); + $this->logService = new LogService(); $this->databaseService = new DatabaseService(); } 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')); diff --git a/README.md b/README.md index 4313611..57f2cb6 100644 --- a/README.md +++ b/README.md @@ -14,17 +14,18 @@ The patterns can be structured in roughly three different categories. Please cli * [AbstractFactory](Creational/AbstractFactory) [:notebook:](http://en.wikipedia.org/wiki/Abstract_factory_pattern) * [Builder](Creational/Builder) [:notebook:](http://en.wikipedia.org/wiki/Builder_pattern) -* [SimpleFactory](Creational/SimpleFactory) * [FactoryMethod](Creational/FactoryMethod) [:notebook:](http://en.wikipedia.org/wiki/Factory_method_pattern) -* [StaticFactory](Creational/StaticFactory) -* [Prototype](Creational/Prototype) [:notebook:](http://en.wikipedia.org/wiki/Prototype_pattern) -* [Pool](Creational/Pool) [:notebook:](http://en.wikipedia.org/wiki/Object_pool_pattern) -* [Singleton](Creational/Singleton) [:notebook:](http://en.wikipedia.org/wiki/Singleton_pattern) (is considered an anti-pattern! :no_entry:) * [Multiton](Creational/Multiton) (is considered an anti-pattern! :no_entry:) +* [Pool](Creational/Pool) [:notebook:](http://en.wikipedia.org/wiki/Object_pool_pattern) +* [Prototype](Creational/Prototype) [:notebook:](http://en.wikipedia.org/wiki/Prototype_pattern) +* [SimpleFactory](Creational/SimpleFactory) +* [Singleton](Creational/Singleton) [:notebook:](http://en.wikipedia.org/wiki/Singleton_pattern) (is considered an anti-pattern! :no_entry:) +* [StaticFactory](Creational/StaticFactory) ### [Structural](Structural) * [Adapter](Structural/Adapter) [:notebook:](http://en.wikipedia.org/wiki/Adapter_pattern) +* [Bridge](Structural/Bridge) [:notebook:](http://en.wikipedia.org/wiki/Bridge_pattern) * [Composite](Structural/Composite) [:notebook:](http://en.wikipedia.org/wiki/Composite_pattern) * [DataMapper](Structural/DataMapper) [:notebook:](http://en.wikipedia.org/wiki/Data_mapper_pattern) * [Decorator](Structural/Decorator) [:notebook:](http://en.wikipedia.org/wiki/Decorator_pattern) @@ -40,6 +41,7 @@ The patterns can be structured in roughly three different categories. Please cli * [Command](Behavioral/Command) [:notebook:](http://en.wikipedia.org/wiki/Command_pattern) * [Iterator](Behavioral/Iterator) [:notebook:](http://en.wikipedia.org/wiki/Iterator_pattern) * [Mediator](Behavioral/Mediator) [:notebook:](http://en.wikipedia.org/wiki/Mediator_pattern) +* [Memento](Memento) [:notebook:](http://en.wikipedia.org/wiki/Memento_pattern) * [NullObject](Behavioral/NullObject) [:notebook:](http://en.wikipedia.org/wiki/Null_Object_pattern) * [Observer](Behavioral/Observer) [:notebook:](http://en.wikipedia.org/wiki/Observer_pattern) * [Specification](Behavioral/Specification) [:notebook:](http://en.wikipedia.org/wiki/Specification_pattern) @@ -61,7 +63,7 @@ To establish a consistent code quality, please check your code using [PHP_CodeSn (The MIT License) -Copyright (c) 2013 Dominik Liebler +Copyright (c) 2014 Dominik Liebler Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/Structural/Bridge/Assemble.php b/Structural/Bridge/Assemble.php new file mode 100644 index 0000000..2b60889 --- /dev/null +++ b/Structural/Bridge/Assemble.php @@ -0,0 +1,12 @@ +expectOutputString('Car Produced Assembled'); + $vehicle->manufacture(); + } + + public function testMotorcycle() + { + $vehicle = new Motorcycle(new Produce(), new Assemble()); + $this->expectOutputString('Motorcycle Produced Assembled'); + $vehicle->manufacture(); + } +} diff --git a/Structural/Bridge/Car.php b/Structural/Bridge/Car.php new file mode 100644 index 0000000..2754199 --- /dev/null +++ b/Structural/Bridge/Car.php @@ -0,0 +1,22 @@ +workShop1->work(); + $this->workShop2->work(); + } +} diff --git a/Structural/Bridge/Motorcycle.php b/Structural/Bridge/Motorcycle.php new file mode 100644 index 0000000..b021ce6 --- /dev/null +++ b/Structural/Bridge/Motorcycle.php @@ -0,0 +1,22 @@ +workShop1->work(); + $this->workShop2->work(); + } +} diff --git a/Structural/Bridge/Produce.php b/Structural/Bridge/Produce.php new file mode 100644 index 0000000..b2b0505 --- /dev/null +++ b/Structural/Bridge/Produce.php @@ -0,0 +1,15 @@ +workShop1 = $workShop1; + $this->workShop2 = $workShop2; + } + + public function manufacture() + { + } +} diff --git a/Structural/Bridge/Workshop.php b/Structural/Bridge/Workshop.php new file mode 100644 index 0000000..dc62886 --- /dev/null +++ b/Structural/Bridge/Workshop.php @@ -0,0 +1,12 @@ + Date: Mon, 5 May 2014 12:00:18 -0300 Subject: [PATCH 16/17] create a Test folder for each pattern --- .../ChainOfResponsibilities/{ => Tests}/ChainTest.php | 2 +- Behavioral/Command/{ => Tests}/CommandTest.php | 2 +- Behavioral/Iterator/{ => Tests}/IteratorTest.php | 2 +- Behavioral/Mediator/{ => Tests}/MediatorTest.php | 2 +- Behavioral/Memento/{ => Tests}/MementoTest.php | 4 +++- Behavioral/NullObject/{ => Tests}/LoggerTest.php | 2 +- Behavioral/Observer/{ => Tests}/ObserverTest.php | 2 +- .../Specification/{ => Tests}/SpecificationTest.php | 2 +- Behavioral/Strategy/{ => Tests}/StrategyTest.php | 2 +- Behavioral/TemplateMethod/{ => Tests}/JourneyTest.php | 2 +- Behavioral/Visitor/{ => Tests}/VisitorTest.php | 2 +- .../AbstractFactory/{ => Tests}/AbstractFactoryTest.php | 2 +- Creational/Builder/{ => Tests}/DirectorTest.php | 2 +- .../FactoryMethod/{ => Tests}/FactoryMethodTest.php | 2 +- Creational/Pool/{ => Tests}/PoolTest.php | 6 ++++-- .../SimpleFactory/{ => Tests}/SimpleFactoryTest.php | 2 +- Creational/Singleton/{ => Tests}/SingletonTest.php | 2 +- .../StaticFactory/{ => Tests}/StaticFactoryTest.php | 2 +- More/Delegation/{ => Tests}/DelegationTest.php | 2 +- More/ServiceLocator/{ => Tests}/ServiceLocatorTest.php | 2 +- Structural/Adapter/{ => Tests}/AdapterTest.php | 2 +- Structural/Bridge/{ => Tests}/BridgeTest.php | 7 ++++++- Structural/Composite/{ => Tests}/CompositeTest.php | 2 +- Structural/DataMapper/{ => Tests}/DataMapperTest.php | 2 +- Structural/Decorator/{ => Tests}/DecoratorTest.php | 2 +- .../{ => Tests}/DependencyInjectionTest.php | 4 +--- Structural/DependencyInjection/{ => Tests}/config.php | 0 Structural/Facade/{ => Tests}/FacadeTest.php | 2 +- .../FluentInterface/{ => Tests}/FluentInterfaceTest.php | 2 +- Structural/Registry/{ => Tests}/RegistryTest.php | 2 +- phpunit.xml.dist | 8 ++++---- 31 files changed, 43 insertions(+), 36 deletions(-) rename Behavioral/ChainOfResponsibilities/{ => Tests}/ChainTest.php (97%) rename Behavioral/Command/{ => Tests}/CommandTest.php (93%) rename Behavioral/Iterator/{ => Tests}/IteratorTest.php (97%) rename Behavioral/Mediator/{ => Tests}/MediatorTest.php (95%) rename Behavioral/Memento/{ => Tests}/MementoTest.php (94%) rename Behavioral/NullObject/{ => Tests}/LoggerTest.php (94%) rename Behavioral/Observer/{ => Tests}/ObserverTest.php (96%) rename Behavioral/Specification/{ => Tests}/SpecificationTest.php (98%) rename Behavioral/Strategy/{ => Tests}/StrategyTest.php (97%) rename Behavioral/TemplateMethod/{ => Tests}/JourneyTest.php (94%) rename Behavioral/Visitor/{ => Tests}/VisitorTest.php (95%) rename Creational/AbstractFactory/{ => Tests}/AbstractFactoryTest.php (95%) rename Creational/Builder/{ => Tests}/DirectorTest.php (95%) rename Creational/FactoryMethod/{ => Tests}/FactoryMethodTest.php (95%) rename Creational/Pool/{ => Tests}/PoolTest.php (69%) rename Creational/SimpleFactory/{ => Tests}/SimpleFactoryTest.php (93%) rename Creational/Singleton/{ => Tests}/SingletonTest.php (92%) rename Creational/StaticFactory/{ => Tests}/StaticFactoryTest.php (90%) rename More/Delegation/{ => Tests}/DelegationTest.php (89%) rename More/ServiceLocator/{ => Tests}/ServiceLocatorTest.php (98%) rename Structural/Adapter/{ => Tests}/AdapterTest.php (95%) rename Structural/Bridge/{ => Tests}/BridgeTest.php (67%) rename Structural/Composite/{ => Tests}/CompositeTest.php (95%) rename Structural/DataMapper/{ => Tests}/DataMapperTest.php (98%) rename Structural/Decorator/{ => Tests}/DecoratorTest.php (97%) rename Structural/DependencyInjection/{ => Tests}/DependencyInjectionTest.php (76%) rename Structural/DependencyInjection/{ => Tests}/config.php (100%) rename Structural/Facade/{ => Tests}/FacadeTest.php (96%) rename Structural/FluentInterface/{ => Tests}/FluentInterfaceTest.php (89%) rename Structural/Registry/{ => Tests}/RegistryTest.php (86%) diff --git a/Behavioral/ChainOfResponsibilities/ChainTest.php b/Behavioral/ChainOfResponsibilities/Tests/ChainTest.php similarity index 97% rename from Behavioral/ChainOfResponsibilities/ChainTest.php rename to Behavioral/ChainOfResponsibilities/Tests/ChainTest.php index 9fe7f30..4733d6f 100644 --- a/Behavioral/ChainOfResponsibilities/ChainTest.php +++ b/Behavioral/ChainOfResponsibilities/Tests/ChainTest.php @@ -1,6 +1,6 @@ get(); $this->assertEquals(1, $worker->id); diff --git a/Creational/SimpleFactory/SimpleFactoryTest.php b/Creational/SimpleFactory/Tests/SimpleFactoryTest.php similarity index 93% rename from Creational/SimpleFactory/SimpleFactoryTest.php rename to Creational/SimpleFactory/Tests/SimpleFactoryTest.php index 1233609..1fffda3 100644 --- a/Creational/SimpleFactory/SimpleFactoryTest.php +++ b/Creational/SimpleFactory/Tests/SimpleFactoryTest.php @@ -1,6 +1,6 @@ - Behavioral - Creational - More - Structural + Behavioral/*/Tests + Creational/*/Tests + More/*/Tests + Structural/*/Tests From bebb52679f5041043b404d9412b53b09fe0e25c1 Mon Sep 17 00:00:00 2001 From: Antonio Spinelli Date: Mon, 5 May 2014 12:06:52 -0300 Subject: [PATCH 17/17] adding a bridge sample --- Structural/Bridge/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Structural/Bridge/README.md b/Structural/Bridge/README.md index 33f8012..6ddc67e 100644 --- a/Structural/Bridge/README.md +++ b/Structural/Bridge/README.md @@ -3,5 +3,7 @@ Decouple an abstraction from its implementation so that the two can vary independently. (http://en.wikipedia.org/wiki/Bridge_pattern) +#### Sample: +* [Symfony DoctrineBridge](https://github.com/symfony/DoctrineBridge)