Guest User

Untitled

a guest
May 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Drupal\Tests\phpunit_example\Unit;
  4.  
  5. use Drupal\Tests\UnitTestCase;
  6. use Drupal\phpunit_example\Unit;
  7.  
  8. /**
  9. * Simple test to ensure that asserts pass.
  10. *
  11. * @group phpunit_example
  12. */
  13. class UnitTest extends UnitTestCase {
  14.  
  15. protected $unit;
  16.  
  17. /**
  18. * Before a test method is run, setUp() is invoked.
  19. * Create new unit object.
  20. */
  21. public function setUp() {
  22. $this->unit = new Unit();
  23. }
  24.  
  25. /**
  26. * @covers Drupal\phpunit_example\Unit::setLength
  27. */
  28. public function testSetLength() {
  29.  
  30. $this->assertEquals(0, $this->unit->getLength());
  31. $this->unit->setLength(9);
  32. $this->assertEquals(9, $this->unit->getLength());
  33. }
  34.  
  35. /**
  36. * @covers Drupal\phpunit_example\Unit::getLength
  37. */
  38. public function testGetLength() {
  39.  
  40. $this->unit->setLength(9);
  41. $this->assertNotEquals(10, $this->unit->getLength());
  42. }
  43.  
  44. /**
  45. * Once test method has finished running, whether it succeeded or failed, tearDown() will be invoked.
  46. * Unset the $unit object.
  47. */
  48. public function tearDown() {
  49. unset($this->unit);
  50. }
  51.  
  52. }
Add Comment
Please, Sign In to add comment