StaticInvocationTest.php 2.5 KB

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