From dfcd62a4e6b25f4c83ca6c04f05acfef9d808b07 Mon Sep 17 00:00:00 2001 From: claudio-dalicandro Date: Mon, 13 Jan 2014 18:27:30 +0100 Subject: [PATCH 1/2] Absolute path for context key --- lib/PUGX/Godfather/Context/Context.php | 3 +-- sf2-bundle/PUGX/GodfatherBundle/Resources/config/services.xml | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/PUGX/Godfather/Context/Context.php b/lib/PUGX/Godfather/Context/Context.php index a4d9903..1cdf7da 100644 --- a/lib/PUGX/Godfather/Context/Context.php +++ b/lib/PUGX/Godfather/Context/Context.php @@ -36,9 +36,8 @@ public function getFallbackStrategy() private function getClassOrType($object) { if (is_object($object)) { - $function = new \ReflectionClass(get_class($object)); - return $function->getShortName(); + return get_class($object); } try { $object = (string) $object; diff --git a/sf2-bundle/PUGX/GodfatherBundle/Resources/config/services.xml b/sf2-bundle/PUGX/GodfatherBundle/Resources/config/services.xml index 97fecbb..ddb2d25 100644 --- a/sf2-bundle/PUGX/GodfatherBundle/Resources/config/services.xml +++ b/sf2-bundle/PUGX/GodfatherBundle/Resources/config/services.xml @@ -10,11 +10,11 @@ - + godfather - + From 14a1ccaf0e26710b028415c6f11243d8917e3169 Mon Sep 17 00:00:00 2001 From: Claudio D'Alicandro Date: Tue, 14 Jan 2014 11:54:05 +0100 Subject: [PATCH 2/2] green tests --- README.markdown | 8 ++++++-- tests/PUGX/Godfather/Test/Context/ContextTest.php | 2 +- tests/PUGX/Godfather/Test/FunctionalTest.php | 8 ++++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/README.markdown b/README.markdown index 05707e7..d649c2b 100644 --- a/README.markdown +++ b/README.markdown @@ -183,6 +183,10 @@ godfather: ### Set your strategies: ```yml +parameters: + mug.class: Mug + tshirt.class: Tshirt + services: manager_standard: class: StandardProductManager @@ -190,12 +194,12 @@ services: manager_mug: class: MugManager tags: - - { name: godfather.strategy, context_name: 'manager', context_key: Mug } + - { name: godfather.strategy, context_name: 'manager', context_key: %mug.class% } manager_tshirt: class: TshirtManager tags: - - { name: godfather.strategy, context_name: 'manager', context_key: Tshirt } + - { name: godfather.strategy, context_name: 'manager', context_key: %tshirt.class% } ``` ### Using in the controller: diff --git a/tests/PUGX/Godfather/Test/Context/ContextTest.php b/tests/PUGX/Godfather/Test/Context/ContextTest.php index aeabbae..4c8ef49 100644 --- a/tests/PUGX/Godfather/Test/Context/ContextTest.php +++ b/tests/PUGX/Godfather/Test/Context/ContextTest.php @@ -17,7 +17,7 @@ public function testGetStrategy() { $context = new Context(new \stdClass()); - $this->assertEquals('ticket', $context->getStrategyName(new Ticket())); + $this->assertEquals('pugx.godfather.test.context.ticket', $context->getStrategyName(new Ticket())); } } diff --git a/tests/PUGX/Godfather/Test/FunctionalTest.php b/tests/PUGX/Godfather/Test/FunctionalTest.php index dccb2e9..0260803 100644 --- a/tests/PUGX/Godfather/Test/FunctionalTest.php +++ b/tests/PUGX/Godfather/Test/FunctionalTest.php @@ -26,10 +26,10 @@ public function testStrategyUsage($godfather, $contextName, $contextKey, $produc public function provider() { return array( - 'SymfonyContainer with the Mug' => array($this->createSymfonyGodfather(), 'manager', 'mug_product', new MugProduct(), 'mug_manager' , 'echo-mug'), - 'SymfonyContainer with the Tshirt' => array($this->createSymfonyGodfather(), 'manager', 'tshirt_product', new TshirtProduct(), 'tshirt_manager', 'echo-tshirt'), - 'ArrayContainer with the Mug' => array($this->createArrayGodfather(), 'manager', 'mug_product', new MugProduct(), 'mug_manager' , 'echo-mug'), - 'ArrayContainer with the Tshirt' => array($this->createArrayGodfather(), 'manager', 'tshirt_product', new TshirtProduct(), 'tshirt_manager', 'echo-tshirt'), + 'SymfonyContainer with the Mug' => array($this->createSymfonyGodfather(), 'manager', 'pugx.godfather.test.fixture.mug_product', new MugProduct(), 'mug_manager' , 'echo-mug'), + 'SymfonyContainer with the Tshirt' => array($this->createSymfonyGodfather(), 'manager', 'pugx.godfather.test.fixture.tshirt_product', new TshirtProduct(), 'tshirt_manager', 'echo-tshirt'), + 'ArrayContainer with the Mug' => array($this->createArrayGodfather(), 'manager', 'pugx.godfather.test.fixture.mug_product', new MugProduct(), 'mug_manager' , 'echo-mug'), + 'ArrayContainer with the Tshirt' => array($this->createArrayGodfather(), 'manager', 'pugx.godfather.test.fixture.tshirt_product', new TshirtProduct(), 'tshirt_manager', 'echo-tshirt'), ); }