dox Executable Documentation

Constructor injection

Empty constructor

Given the class definition 'class SomeClass {}'
When I get 'SomeClass' from the factory
Then the object should be an instance of 'SomeClass'

Constructor arguments

Given the class definition 'class ClassWithConstructor { function __construct($arg1, $arg2) { $this->msg = $arg1 . $arg2; } }'
When I get 'ClassWithConstructor' with arguments array('arg2' => ' World', 'arg1' => 'Hello') from the factory
Then the object should be an instance of 'ClassWithConstructor'
Then the the property 'msg' of the object should be 'Hello World'

Constructor arguments in list

Given the class definition 'class ClassWithConstructorInList { function __construct($arg1, $arg2) { $this->msg = $arg1 . $arg2; } }'
When I get 'ClassWithConstructorInList' with arguments array('Hello', ' You') from the factory
Then the the property 'msg' of the object should be 'Hello You'

Constructor arguments mixed

Given the class definition 'class ClassWithConstructorMixed { function __construct($arg1, $arg2) { $this->msg = $arg1 . $arg2; } }'
When I get 'ClassWithConstructorMixed' with arguments array('arg2' => ' World', 0 => 'Hello') from the factory
Then the the property 'msg' of the object should be 'Hello World'

Default arguments

Given the class definition 'class DefaultArguments { function __construct($argRequired, $argDefault = " World") { $this->msg = $argRequired . $argDefault; } }'
When I get 'DefaultArguments' with arguments array('argRequired' => 'Hello') from the factory
Then the object should be an instance of 'DefaultArguments'
Then the the property 'msg' of the object should be 'Hello World'

Dont inject default argument

Given the class definition 'class DontInjectDefaultArgument { function __construct(StdClass $dont = null) { $this->dont = $dont; } }'
When I get 'DontInjectDefaultArgument' from the factory
Then the object should be an instance of 'DontInjectDefaultArgument'
Then the the property 'dont' of the object should be null

Missing arguments

Given the class definition 'class MissingArgument { function __construct($arg1, $arg2) { $this->msg = $arg1 . $arg2; } }'
When I try to get 'MissingArgument' with arguments array('arg2' => 'Not enough') from the factory
Then an exception should be thrown
Then an exception message should contain 'Cannot inject parameter [arg1] of [MissingArgument::__construct]'

Inject arguments by factory

Given the class definition 'class InjectMe { function __construct($msg = "Hello World") { $this->greeting = $msg; } }'
Given the class definition 'class InjectingOne { function __construct(InjectMe $arg1) { $this->msg = $arg1->greeting; } }'
When I get 'InjectingOne' from the factory
Then the the property 'msg' of the object should be 'Hello World'

Mix given and injected arguments

Given the class definition 'class InjectMeToo { function __construct($msg = "Hello") { $this->greeting = $msg; } }'
Given the class definition 'class InjectingTwo { function __construct(InjectMeToo $arg1, $arg2, $arg3 = "!") { $this->msg = $arg1->greeting . $arg2 . $arg3; } }'
When I get 'InjectingTwo' with arguments array('arg2' => ' World') from the factory
Then the the property 'msg' of the object should be 'Hello World!'

Inject factory

Given the class definition 'class InjectFactory { function __construct(\\watoki\\factory\\Factory $factory) { $this->factory = $factory; } }'
When I get 'InjectFactory' from the factory
Then the the property 'factory' of the object should be the factory

Recursive injection

Given the class definition 'class RecursiveInjectionOne { function __construct($msg = "Hello") { $this->msg = $msg; } }'
Given the class definition 'class RecursiveInjectionTwo { function __construct(RecursiveInjectionOne $one, $msg = " World") { $this->msg = $one->msg . $msg; } }'
Given the class definition 'class RecursiveInjectionThree { function __construct(RecursiveInjectionTwo $two) { $this->msg = $two->msg; } }'
When I get 'RecursiveInjectionThree' from the factory
Then the the property 'msg' of the object should be 'Hello World'

Optional class argument

Given the class definition 'class OptionalClassArgument { function __construct(\\DateTime $date = null) { $this->date = $date; } }'
When I get 'OptionalClassArgument' from the factory
Then the the property 'date' of the object should be null

Doc comment type hints

Given the class definition 'class DocCommentHints { /** * @param StdClass $one * @param DateTime $two * @param StdClass $three * @param object $four */ function __construct($one, StdClass $two, $three = "foo", $four = "bar") { $this->one = $one; $this->two = $two; $this->three = $three; $this->four = $four; } }'
When I get 'DocCommentHints' from the factory
Then the the property 'one' of the object should be an instance of 'StdClass'
Then the the property 'two' of the object should be an instance of 'StdClass'
Then the the property 'three' of the object should be 'foo'
Then the the property 'four' of the object should be 'bar'

Relative type hints

Given the class definition 'namespace one\\two; class RelativeDependency {}'
Given the class definition ' namespace one; class RelativeTypeHints { /** * @param two\\RelativeDependency $one */ function __construct($one) { $this->one = $one; } }'
When I get 'one\\RelativeTypeHints' from the factory
Then the the property 'one' of the object should be an instance of 'one\\two\\RelativeDependency'

Abstract dependency

Given the class definition 'abstract class AbstractDependency {}'
Given the class definition 'class HasAbstractDependency { function __construct(AbstractDependency $itsAbstract) {} }'
When I try to get 'HasAbstractDependency' from the factory
Then an exception should be thrown

Interface dependency

Given the class definition 'interface InterfaceDependency {}'
Given the class definition 'class HasInterfaceDependency { function __construct(InterfaceDependency $itsAbstract) {} }'
When I try to get 'HasInterfaceDependency' from the factory
Then an exception should be thrown