DefinitionTest.php 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /*
  3. * This file is part of the symfony package.
  4. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. require_once __DIR__.'/../../../bootstrap.php';
  10. use Symfony\Components\DependencyInjection\Definition;
  11. $t = new LimeTest(21);
  12. // __construct()
  13. $t->diag('__construct()');
  14. $def = new Definition('stdClass');
  15. $t->is($def->getClass(), 'stdClass', '__construct() takes the class name as its first argument');
  16. $def = new Definition('stdClass', array('foo'));
  17. $t->is($def->getArguments(), array('foo'), '__construct() takes an optional array of arguments as its second argument');
  18. // ->setConstructor() ->getConstructor()
  19. $t->diag('->setConstructor() ->getConstructor()');
  20. $def = new Definition('stdClass');
  21. $t->is(spl_object_hash($def->setConstructor('foo')), spl_object_hash($def), '->setConstructor() implements a fluent interface');
  22. $t->is($def->getConstructor(), 'foo', '->getConstructor() returns the constructor name');
  23. // ->setClass() ->getClass()
  24. $t->diag('->setClass() ->getClass()');
  25. $def = new Definition('stdClass');
  26. $t->is(spl_object_hash($def->setClass('foo')), spl_object_hash($def), '->setClass() implements a fluent interface');
  27. $t->is($def->getClass(), 'foo', '->getClass() returns the class name');
  28. // ->setArguments() ->getArguments() ->addArgument()
  29. $t->diag('->setArguments() ->getArguments() ->addArgument()');
  30. $def = new Definition('stdClass');
  31. $t->is(spl_object_hash($def->setArguments(array('foo'))), spl_object_hash($def), '->setArguments() implements a fluent interface');
  32. $t->is($def->getArguments(), array('foo'), '->getArguments() returns the arguments');
  33. $t->is(spl_object_hash($def->addArgument('bar')), spl_object_hash($def), '->addArgument() implements a fluent interface');
  34. $t->is($def->getArguments(), array('foo', 'bar'), '->addArgument() adds an argument');
  35. // ->setMethodCalls() ->getMethodCalls() ->addMethodCall()
  36. $t->diag('->setMethodCalls() ->getMethodCalls() ->addMethodCall()');
  37. $def = new Definition('stdClass');
  38. $t->is(spl_object_hash($def->setMethodCalls(array(array('foo', array('foo'))))), spl_object_hash($def), '->setMethodCalls() implements a fluent interface');
  39. $t->is($def->getMethodCalls(), array(array('foo', array('foo'))), '->getMethodCalls() returns the methods to call');
  40. $t->is(spl_object_hash($def->addMethodCall('bar', array('bar'))), spl_object_hash($def), '->addMethodCall() implements a fluent interface');
  41. $t->is($def->getMethodCalls(), array(array('foo', array('foo')), array('bar', array('bar'))), '->addMethodCall() adds a method to call');
  42. // ->setFile() ->getFile()
  43. $t->diag('->setFile() ->getFile()');
  44. $def = new Definition('stdClass');
  45. $t->is(spl_object_hash($def->setFile('foo')), spl_object_hash($def), '->setFile() implements a fluent interface');
  46. $t->is($def->getFile(), 'foo', '->getFile() returns the file to include');
  47. // ->setShared() ->isShared()
  48. $t->diag('->setShared() ->isShared()');
  49. $def = new Definition('stdClass');
  50. $t->is($def->isShared(), true, '->isShared() returns true by default');
  51. $t->is(spl_object_hash($def->setShared(false)), spl_object_hash($def), '->setShared() implements a fluent interface');
  52. $t->is($def->isShared(), false, '->isShared() returns false if the instance must not be shared');
  53. // ->setConfigurator() ->getConfigurator()
  54. $t->diag('->setConfigurator() ->getConfigurator()');
  55. $def = new Definition('stdClass');
  56. $t->is(spl_object_hash($def->setConfigurator('foo')), spl_object_hash($def), '->setConfigurator() implements a fluent interface');
  57. $t->is($def->getConfigurator(), 'foo', '->getConfigurator() returns the configurator');