Drupal investigation

MockBuilderTest.php 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /*
  3. * This file is part of the PHPUnit_MockObject 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. /**
  11. * @since File available since Release 1.0.0
  12. */
  13. class Framework_MockBuilderTest extends PHPUnit_Framework_TestCase
  14. {
  15. public function testMockBuilderRequiresClassName()
  16. {
  17. $spec = $this->getMockBuilder('Mockable');
  18. $mock = $spec->getMock();
  19. $this->assertTrue($mock instanceof Mockable);
  20. }
  21. public function testByDefaultMocksAllMethods()
  22. {
  23. $spec = $this->getMockBuilder('Mockable');
  24. $mock = $spec->getMock();
  25. $this->assertNull($mock->mockableMethod());
  26. $this->assertNull($mock->anotherMockableMethod());
  27. }
  28. public function testMethodsToMockCanBeSpecified()
  29. {
  30. $spec = $this->getMockBuilder('Mockable');
  31. $spec->setMethods(array('mockableMethod'));
  32. $mock = $spec->getMock();
  33. $this->assertNull($mock->mockableMethod());
  34. $this->assertTrue($mock->anotherMockableMethod());
  35. }
  36. public function testByDefaultDoesNotPassArgumentsToTheConstructor()
  37. {
  38. $spec = $this->getMockBuilder('Mockable');
  39. $mock = $spec->getMock();
  40. $this->assertEquals(array(null, null), $mock->constructorArgs);
  41. }
  42. public function testMockClassNameCanBeSpecified()
  43. {
  44. $spec = $this->getMockBuilder('Mockable');
  45. $spec->setMockClassName('ACustomClassName');
  46. $mock = $spec->getMock();
  47. $this->assertTrue($mock instanceof ACustomClassName);
  48. }
  49. public function testConstructorArgumentsCanBeSpecified()
  50. {
  51. $spec = $this->getMockBuilder('Mockable');
  52. $spec->setConstructorArgs($expected = array(23, 42));
  53. $mock = $spec->getMock();
  54. $this->assertEquals($expected, $mock->constructorArgs);
  55. }
  56. public function testOriginalConstructorCanBeDisabled()
  57. {
  58. $spec = $this->getMockBuilder('Mockable');
  59. $spec->disableOriginalConstructor();
  60. $mock = $spec->getMock();
  61. $this->assertNull($mock->constructorArgs);
  62. }
  63. public function testByDefaultOriginalCloneIsPreserved()
  64. {
  65. $spec = $this->getMockBuilder('Mockable');
  66. $mock = $spec->getMock();
  67. $cloned = clone $mock;
  68. $this->assertTrue($cloned->cloned);
  69. }
  70. public function testOriginalCloneCanBeDisabled()
  71. {
  72. $spec = $this->getMockBuilder('Mockable');
  73. $spec->disableOriginalClone();
  74. $mock = $spec->getMock();
  75. $mock->cloned = false;
  76. $cloned = clone $mock;
  77. $this->assertFalse($cloned->cloned);
  78. }
  79. public function testCallingAutoloadCanBeDisabled()
  80. {
  81. // it is not clear to me how to test this nor the difference
  82. // between calling it or not
  83. $this->markTestIncomplete();
  84. }
  85. public function testProvidesAFluentInterface()
  86. {
  87. $spec = $this->getMockBuilder('Mockable')
  88. ->setMethods(array('mockableMethod'))
  89. ->setConstructorArgs(array())
  90. ->setMockClassName('DummyClassName')
  91. ->disableOriginalConstructor()
  92. ->disableOriginalClone()
  93. ->disableAutoload();
  94. $this->assertTrue($spec instanceof PHPUnit_Framework_MockObject_MockBuilder);
  95. }
  96. }