AssertsTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. class AssertsTest extends PHPUnit_Framework_TestCase
  3. {
  4. public function testAsserts()
  5. {
  6. $module = new \Codeception\Module\Asserts(make_container());
  7. $module->assertEquals(1, 1);
  8. $module->assertContains(1, [1, 2]);
  9. $module->assertSame(1, 1);
  10. $module->assertNotSame(1, '1');
  11. $module->assertRegExp('/^[\d]$/', '1');
  12. $module->assertNotRegExp('/^[a-z]$/', '1');
  13. $module->assertEmpty([]);
  14. $module->assertNotEmpty([1]);
  15. $module->assertNull(null);
  16. $module->assertNotNull('');
  17. $module->assertNotNull(false);
  18. $module->assertNotNull(0);
  19. $module->assertTrue(true);
  20. $module->assertFalse(false);
  21. $module->assertFileExists(__FILE__);
  22. $module->assertFileNotExists(__FILE__ . '.notExist');
  23. $module->assertInstanceOf('Exception', new Exception());
  24. $module->assertInternalType('integer', 5);
  25. $module->assertArrayHasKey('one', ['one' => 1, 'two' => 2]);
  26. $module->assertCount(3, [1, 2, 3]);
  27. }
  28. public function testExceptions()
  29. {
  30. $module = new \Codeception\Module\Asserts(make_container());
  31. $module->expectException('Exception', function () {
  32. throw new Exception;
  33. });
  34. $module->expectException(new Exception('here'), function () {
  35. throw new Exception('here');
  36. });
  37. $module->expectException(new Exception('here', 200), function () {
  38. throw new Exception('here', 200);
  39. });
  40. }
  41. /**
  42. * @expectedException PHPUnit_Framework_AssertionFailedError
  43. */
  44. public function testExceptionFails()
  45. {
  46. $module = new \Codeception\Module\Asserts(make_container());
  47. $module->expectException(new Exception('here', 200), function () {
  48. throw new Exception('here', 2);
  49. });
  50. }
  51. }