StaticTest.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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\TestCase;
  11. class Framework_MockObject_Invocation_StaticTest extends TestCase
  12. {
  13. public function testConstructorRequiresClassAndMethodAndParameters()
  14. {
  15. $this->assertInstanceOf(
  16. PHPUnit_Framework_MockObject_Invocation_Static::class,
  17. new PHPUnit_Framework_MockObject_Invocation_Static(
  18. 'FooClass',
  19. 'FooMethod',
  20. ['an_argument'],
  21. 'ReturnType'
  22. )
  23. );
  24. }
  25. public function testAllowToGetClassNameSetInConstructor()
  26. {
  27. $invocation = new PHPUnit_Framework_MockObject_Invocation_Static(
  28. 'FooClass',
  29. 'FooMethod',
  30. ['an_argument'],
  31. 'ReturnType'
  32. );
  33. $this->assertSame('FooClass', $invocation->className);
  34. }
  35. public function testAllowToGetMethodNameSetInConstructor()
  36. {
  37. $invocation = new PHPUnit_Framework_MockObject_Invocation_Static(
  38. 'FooClass',
  39. 'FooMethod',
  40. ['an_argument'],
  41. 'ReturnType'
  42. );
  43. $this->assertSame('FooMethod', $invocation->methodName);
  44. }
  45. public function testAllowToGetMethodParametersSetInConstructor()
  46. {
  47. $expectedParameters = [
  48. 'foo', 5, ['a', 'b'], new stdClass, null, false
  49. ];
  50. $invocation = new PHPUnit_Framework_MockObject_Invocation_Static(
  51. 'FooClass',
  52. 'FooMethod',
  53. $expectedParameters,
  54. 'ReturnType'
  55. );
  56. $this->assertSame($expectedParameters, $invocation->parameters);
  57. }
  58. public function testConstructorAllowToSetFlagCloneObjectsInParameters()
  59. {
  60. $parameters = [new stdClass];
  61. $cloneObjects = true;
  62. $invocation = new PHPUnit_Framework_MockObject_Invocation_Static(
  63. 'FooClass',
  64. 'FooMethod',
  65. $parameters,
  66. 'ReturnType',
  67. $cloneObjects
  68. );
  69. $this->assertEquals($parameters, $invocation->parameters);
  70. $this->assertNotSame($parameters, $invocation->parameters);
  71. }
  72. public function testAllowToGetReturnTypeSetInConstructor()
  73. {
  74. $expectedReturnType = 'string';
  75. $invocation = new PHPUnit_Framework_MockObject_Invocation_Static(
  76. 'FooClass',
  77. 'FooMethod',
  78. ['an_argument'],
  79. $expectedReturnType
  80. );
  81. $this->assertSame($expectedReturnType, $invocation->returnType);
  82. }
  83. }