ObjectInvocationTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /*
  3. * This file is part of the phpunit-mock-objects package.
  4. *
  5. * (c) Sebastian Bergmann <sebastian@phpunit.de>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. use PHPUnit\Framework\MockObject\Invocation\ObjectInvocation;
  11. use PHPUnit\Framework\TestCase;
  12. class ObjectInvocationTest extends TestCase
  13. {
  14. public function testConstructorRequiresClassAndMethodAndParametersAndObject()
  15. {
  16. $this->assertInstanceOf(
  17. ObjectInvocation::class,
  18. new ObjectInvocation(
  19. 'FooClass',
  20. 'FooMethod',
  21. ['an_argument'],
  22. 'ReturnType',
  23. new stdClass
  24. )
  25. );
  26. }
  27. public function testAllowToGetClassNameSetInConstructor()
  28. {
  29. $invocation = new ObjectInvocation(
  30. 'FooClass',
  31. 'FooMethod',
  32. ['an_argument'],
  33. 'ReturnType',
  34. new stdClass
  35. );
  36. $this->assertSame('FooClass', $invocation->getClassName());
  37. }
  38. public function testAllowToGetMethodNameSetInConstructor()
  39. {
  40. $invocation = new ObjectInvocation(
  41. 'FooClass',
  42. 'FooMethod',
  43. ['an_argument'],
  44. 'ReturnType',
  45. new stdClass
  46. );
  47. $this->assertSame('FooMethod', $invocation->getMethodName());
  48. }
  49. public function testAllowToGetObjectSetInConstructor()
  50. {
  51. $expectedObject = new stdClass;
  52. $invocation = new ObjectInvocation(
  53. 'FooClass',
  54. 'FooMethod',
  55. ['an_argument'],
  56. 'ReturnType',
  57. $expectedObject
  58. );
  59. $this->assertSame($expectedObject, $invocation->getObject());
  60. }
  61. public function testAllowToGetMethodParametersSetInConstructor()
  62. {
  63. $expectedParameters = [
  64. 'foo', 5, ['a', 'b'], new stdClass, null, false
  65. ];
  66. $invocation = new ObjectInvocation(
  67. 'FooClass',
  68. 'FooMethod',
  69. $expectedParameters,
  70. 'ReturnType',
  71. new stdClass
  72. );
  73. $this->assertSame($expectedParameters, $invocation->getParameters());
  74. }
  75. public function testConstructorAllowToSetFlagCloneObjectsInParameters()
  76. {
  77. $parameters = [new stdClass];
  78. $cloneObjects = true;
  79. $invocation = new ObjectInvocation(
  80. 'FooClass',
  81. 'FooMethod',
  82. $parameters,
  83. 'ReturnType',
  84. new stdClass,
  85. $cloneObjects
  86. );
  87. $this->assertEquals($parameters, $invocation->getParameters());
  88. $this->assertNotSame($parameters, $invocation->getParameters());
  89. }
  90. public function testAllowToGetReturnTypeSetInConstructor()
  91. {
  92. $expectedReturnType = 'string';
  93. $invocation = new ObjectInvocation(
  94. 'FooClass',
  95. 'FooMethod',
  96. ['an_argument'],
  97. $expectedReturnType,
  98. new stdClass
  99. );
  100. $this->assertSame($expectedReturnType, $invocation->getReturnType());
  101. }
  102. }