コード例 #1
0
ファイル: LeafImpl.php プロジェクト: trismegiste/php-is-magic
 public function setParent(Composite $parent)
 {
     $this->parentNode = $parent;
     if (!$parent->contains($this)) {
         $parent->append($this);
     }
 }
コード例 #2
0
 /**
  * @dataProvider paymentMethodDataProvider
  * @param bool $expectation
  */
 public function testIsApplicable($expectation)
 {
     $quote = $this->getMockBuilder('Magento\\Sales\\Model\\Quote')->disableOriginalConstructor()->setMethods([])->getMock();
     $paymentMethod = $this->getMockBuilder('Magento\\Payment\\Model\\Checks\\PaymentMethodChecksInterface')->disableOriginalConstructor()->setMethods([])->getMock();
     $specification = $this->getMockBuilder('Magento\\Payment\\Model\\Checks\\SpecificationInterface')->disableOriginalConstructor()->setMethods([])->getMock();
     $specification->expects($this->once())->method('isApplicable')->with($paymentMethod, $quote)->will($this->returnValue($expectation));
     $model = new Composite([$specification]);
     $this->assertEquals($expectation, $model->isApplicable($paymentMethod, $quote));
 }
コード例 #3
0
 public function testRender()
 {
     $text = 'some text';
     $arguments = ['arg1', 'arg2'];
     $resultAfterFirst = 'rendered text first';
     $resultAfterSecond = 'rendered text second';
     $this->rendererOne->expects($this->once())->method('render')->with([$text], $arguments)->will($this->returnValue($resultAfterFirst));
     $this->rendererTwo->expects($this->once())->method('render')->with([$text, $resultAfterFirst], $arguments)->will($this->returnValue($resultAfterSecond));
     $this->assertEquals($resultAfterSecond, $this->object->render([$text], $arguments));
 }
コード例 #4
0
ファイル: CompositeTest.php プロジェクト: puwenhan/Ferret
 public function testDetectFail()
 {
     $stub = $this->getMock("Versionable\\Ferret\\Detector\\DetectorInterface");
     $stub->expects($this->any())->method('detect')->will($this->returnValue(false));
     $this->object->addDetector($stub);
     $stub = $this->getMock("Versionable\\Ferret\\Detector\\DetectorInterface");
     $stub->expects($this->any())->method('detect')->will($this->returnValue(false));
     $this->object->addDetector($stub);
     $this->assertFalse($this->object->detect('data/unit.false'));
 }
コード例 #5
0
 public function testHandle()
 {
     $factoryMock = $this->getMock('\\Magento\\Catalog\\Controller\\Adminhtml\\Product\\Initialization\\Helper\\HandlerFactory', [], [], '', false);
     $constructorMock = $this->getMock('\\Magento\\Catalog\\Controller\\Adminhtml\\Product\\Initialization\\Helper\\HandlerInterface');
     $factoryMock->expects($this->exactly(2))->method('create')->with('handlerInstance')->will($this->returnValue($constructorMock));
     $productMock = $this->getMock('\\Magento\\Catalog\\Model\\Product', [], [], '', false);
     $constructorMock->expects($this->exactly(2))->method('handle')->with($productMock);
     $model = new Composite($factoryMock, ['handlerInstance', 'handlerInstance']);
     $model->handle($productMock);
 }
コード例 #6
0
 public function testComposite()
 {
     $root = new Composite();
     $root->doSomething();
     $branch = new Composite();
     $leaf = new Leaf();
     $root->add($branch);
     $branch->add($leaf);
     $this->display($root);
 }
コード例 #7
0
 public function testGetPatternDirs()
 {
     $inputParams = ['param_one' => 'value_one', 'param_two' => 'value_two'];
     $ruleOne = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\Design\\Fallback\\Rule\\RuleInterface');
     $ruleOne->expects($this->once())->method('getPatternDirs')->with($inputParams)->will($this->returnValue(['rule_one/path/one', 'rule_one/path/two']));
     $ruleTwo = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\Design\\Fallback\\Rule\\RuleInterface');
     $ruleTwo->expects($this->once())->method('getPatternDirs')->with($inputParams)->will($this->returnValue(['rule_two/path/one', 'rule_two/path/two']));
     $object = new Composite([$ruleOne, $ruleTwo]);
     $expectedResult = ['rule_one/path/one', 'rule_one/path/two', 'rule_two/path/one', 'rule_two/path/two'];
     $this->assertEquals($expectedResult, $object->getPatternDirs($inputParams));
 }
コード例 #8
0
ファイル: DepthCalculator.php プロジェクト: bgarrels/ebnf
 /**
  * Calculates the depth on each call.
  *
  * It will return at least 1 if the subject node as no children.
  *
  * @return int
  */
 public function depth()
 {
     if (!$this->node->hasChildren()) {
         return 1;
     }
     $depths = array();
     foreach ($this->node->getIterator() as $subnode) {
         $depths[] = $subnode->depth();
     }
     return max($depths) + 1;
 }
コード例 #9
0
 /**
  *
  */
 public function testReturnsKeyValueWhenAllContainedArrayAccessObjectsHaveThisKeyValuePair2()
 {
     $composite = new Composite();
     $keyValue1 = new \ArrayIterator();
     $composite->attach($keyValue1);
     $keyValue2 = new \ArrayIterator();
     $composite->attach($keyValue2);
     $key = 'Key';
     $value = 'Value';
     $composite[$key] = $value;
     $this->assertEquals($value, $composite[$key]);
 }
コード例 #10
0
ファイル: composite.php プロジェクト: adollar/patterns
 public function __construct()
 {
     $this->root = new Composite("Root");
     $n1 = new Composite("Composite 1");
     $n1->add(new Leaf("Composite1 -> Leaf1"));
     $n1->add(new Leaf("Composite1 -> Leaf2"));
     $this->root->add($n1);
     $n2 = new Composite("Composite2");
     $n2->add(new Leaf("Composite2 -> Leaf1"));
     $n2->add(new Leaf("Composite2 -> Leaf2"));
     $n2->add(new Leaf("Composite2 -> Leaf3"));
     $this->root->add($n2);
     $this->root->add(new Leaf("Root -> Leaf1"));
     $this->root->operation();
 }
コード例 #11
0
ファイル: View.php プロジェクト: rcastardo/mvc-na-pratica
 public function __construct()
 {
     parent::__construct();
     $this->script = array();
     $this->style = array();
     $this->title = 'Sem título';
 }
コード例 #12
0
ファイル: Notx.php プロジェクト: brighttalk/acs-query-builder
 /**
  * @param ExpressionInterface|array $part
  */
 public function __construct($part)
 {
     $parentArgs = array();
     if ($part instanceof ExpressionInterface) {
         $parentArgs[] = $part;
     } elseif (is_array($part)) {
         $parentArgs = $part;
     }
     parent::__construct($parentArgs);
 }
コード例 #13
0
 /**
  * Remove esse componente da lista de filhos de seu pai.
  * @return	Component Uma referência ao próprio Component
  * @throws	BadMethodCallException Se esse componente não possuir
  * 			um pai.
  */
 public function setOrphan()
 {
     if ($this->parent !== null) {
         if ($this->parent->contains($this)) {
             $this->parent->removeChild($this);
         }
         $this->parent = null;
         return $this;
     } else {
         throw new BadMethodCallException('Esse componente não possui um pai.');
     }
 }
コード例 #14
0
ファイル: Composite.php プロジェクト: dmamills/composite
 public function execute()
 {
     if (!file_exists($this->overlay)) {
         throw new \Exception('Overlay image not found.');
     }
     if (!file_exists($this->base)) {
         throw new \Exception('Base image not found.');
     }
     $results = array();
     $command = Composite::prepareCommandString();
     echo 'Executing command: ' . $command;
     exec($command, $results);
     $this->executed = true;
     //parse results for errors/success
     return $results;
 }
コード例 #15
0
 /**
  *
  */
 public function testCallsAllAttachedCallbacksWhenInvoked()
 {
     $composite = new Composite();
     $parameter = new \stdClass();
     $callbackAttached1 = $this->createCallbackMock($this->once(), $parameter);
     $composite->attach($callbackAttached1);
     $callbackNotAttached1 = $this->createCallbackMock($this->never());
     $composite->attach($callbackNotAttached1);
     $callbackAttached2 = $this->createCallbackMock($this->once(), $parameter);
     $composite->attach($callbackAttached2);
     $callbackNotAttached2 = $this->createCallbackMock($this->never());
     $composite->attach($callbackNotAttached2);
     $composite->detach($callbackNotAttached1);
     $composite->detach($callbackNotAttached2);
     $composite($parameter);
 }
コード例 #16
0
 /**
  * @param string $ID
  * @param string $name
  */
 public function __construct($ID, $name)
 {
     $this->ID = $ID;
     $this->name = $name;
     parent::__construct();
 }
コード例 #17
0
ファイル: composite.php プロジェクト: luisOO/design-patterns
 public static function main()
 {
     $leaf1 = new Leaf('first leaf');
     $leaf2 = new Leaf('second leaf');
     $composite = new Composite();
     $composite->add($leaf1);
     $composite->add($leaf2);
     $composite->operate();
     $composite->remove($leaf2);
     $composite->operate();
     $composite->remove($leaf1);
     $leaf1 = null;
     $leaf2 = null;
     $composite = null;
 }
コード例 #18
0
ファイル: CompositeWiki.php プロジェクト: manachyn/trainings
// определяет поведение примитивных объектов в композиции;
class Leaf extends Component
{
    public function add(Component $c)
    {
        print "Cannot add to a leaf";
    }
    public function remove(Component $c)
    {
        print "Cannot remove from a leaf";
    }
    public function display()
    {
        print_r($this->name);
    }
}
// Create a tree structure
$root = new Composite("root");
$root->add(new Leaf("Leaf A"));
$root->add(new Leaf("Leaf B"));
$comp = new Composite("Composite X");
$comp->add(new Leaf("Leaf XA"));
$comp->add(new Leaf("Leaf XB"));
$root->add($comp);
$root->add(new Leaf("Leaf C"));
// Add and remove a leaf
$leaf = new Leaf("Leaf D");
$root->add($leaf);
$root->remove($leaf);
// Recursively display tree
$root->display();
コード例 #19
0
ファイル: index.php プロジェクト: vlasov2312/patterns
    public function GetChildren()
    {
        return $this->_children;
    }
}
class Leaf extends Component
{
    public function Add(Component $Component)
    {
        throw new ComponentException("I can't append child to myself");
    }
    public function GetChild($index)
    {
        throw new ComponentException("Child not exists");
    }
    public function Operation()
    {
        print "I am leaf\n";
    }
    public function Remove($index)
    {
        throw new ComponentException("Child not exists");
    }
    public function GetChildren()
    {
        return array();
    }
}
$composite = new Composite();
$composite->Add(new Leaf());
$composite->Operation();
コード例 #20
0
 /**
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage Argument interpreter named 'one' has already been defined
  *
  */
 public function testAddInterpreterException()
 {
     $newInterpreter = $this->getMock('Magento\\Framework\\Data\\Argument\\InterpreterInterface');
     $this->_model->addInterpreter('one', $newInterpreter);
 }
コード例 #21
0
ファイル: Iterator.php プロジェクト: trismegiste/php-is-magic
 public function __construct(Composite $node)
 {
     $this->branch = $node->getIterator();
 }
コード例 #22
0
    {
        if (isset($this->items[$component->GetName()])) {
            return $this->items[$component->GetName()];
        }
        return null;
    }
    public function GetName() : string
    {
        return $this->name;
    }
    public function SetName(string $value)
    {
        $this->name = $value;
    }
}
$product = new Composite("Product");
$a = new Composite("Part A");
$b = new Composite("Part B");
$c = new Composite("Part C");
$a->Add(new Single("Sub Part A-1"));
$a->Add(new Single("Sub Part A-2"));
$a->Add(new Single("Sub Part A-3"));
$a->Add(new Single("Sub Part A-4"));
$b->Add(new Single("Sub Part B-1"));
$b->Add(new Single("Sub Part B-2"));
$c->Add(new Single("Sub Part C-1"));
$c->Add(new Single("Sub Part C-2"));
$c->Add(new Single("Sub Part C-3"));
$product->Add($a);
$product->Add($b);
$product->Add($c);
コード例 #23
0
class ConcreteComponent implements ComponentInterface
{
    protected $name;
    public function __construct($name)
    {
        $this->name = $name;
    }
    public function operation()
    {
        echo '[' . $this->name . '] operation done';
    }
}
class Composite implements ComponentInterface
{
    protected $components = array();
    public function add(ComponentInterface $component)
    {
        $this->components[] = $component;
    }
    public function operation()
    {
        foreach ($this->components as $component) {
            $component->operation();
        }
    }
}
$composite = new Composite();
$composite->add(new ConcreteComponent('FirstComponent'));
$composite->add(new ConcreteComponent('SecondComponent'));
$composite->add(new ConcreteComponent('ThirdComponent'));
$composite->operation();
コード例 #24
0
ファイル: AndX.php プロジェクト: j0k3r/rulerz
 public function __construct(array $specifications = [])
 {
     parent::__construct('AND', $specifications);
 }
コード例 #25
0
ファイル: Composite.php プロジェクト: popovdenis/lessons-1
    {
        return $this->name;
    }
    public function add(Component $Component)
    {
        throw new ComponentException("I can't append child to myself");
    }
    public function getChild($index)
    {
        throw new ComponentException("Child not exists");
    }
    public function operation()
    {
        print "I am leaf '{$this->name}' <br >";
    }
    public function remove($index)
    {
        throw new ComponentException("Child not exists");
    }
    public function getChildren()
    {
        return array();
    }
}
$composite = new Composite();
$composite->add(new Leaf('First'));
$composite->add(new Leaf('Second'));
$composite->add(new Leaf('Third'));
$composite->add(new Leaf('Fourth'));
$composite->add(new Leaf('Fifth'));
$composite->operation();
コード例 #26
0
ファイル: swap_db.php プロジェクト: usaphp/listafe
 function run_component_proba()
 {
     // Create a tree structure
     $root = new Composite("root");
     $root->Add(new Leaf("Leaf A"));
     $root->Add(new Leaf("Leaf B"));
     $comp = new Composite("Composite X");
     $comp->Add(new Leaf("Leaf XA"));
     $comp->Add(new Leaf("Leaf XB"));
     $root->Add($comp);
     $root->Add(new Leaf("Leaf C"));
     // Add and remove a leaf
     $leaf = new Leaf("Leaf D");
     $root->Add($leaf);
     $root->Remove($leaf);
     // Recursively display tree
     $root->Display();
 }