Skip to content

Commit 322cd64

Browse files
committed
merged 2.1
2 parents 77619d9 + 398f8f4 commit 322cd64

File tree

2 files changed

+49
-36
lines changed

2 files changed

+49
-36
lines changed

src/Codeception/Module/Asserts.php

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -361,32 +361,38 @@ public function fail($message)
361361
* @param $callback
362362
*/
363363
public function expectException($exception, $callback)
364-
{
365-
$code = null;
366-
$msg = null;
367-
if (is_object($exception)) {
368-
/** @var $exception \Exception **/
364+
{
365+
$code = null;
366+
$msg = null;
367+
if (is_object($exception)) {
368+
/** @var $exception \Exception **/
369369
$class = get_class($exception);
370-
$msg = $exception->getMessage();
371-
$code = $exception->getCode();
372-
} else {
373-
$class = $exception;
374-
}
375-
try {
376-
$callback();
377-
} catch (\Exception $e) {
378-
if (!$e instanceof $class) {
379-
$this->fail(sprintf("Exception of class $class expected to be thrown, but %s caught", get_class($e)));
380-
}
381-
if (null !== $msg and $e->getMessage() !== $msg) {
382-
$this->fail(sprintf("Exception of $class expected to be '$msg', but actual message was '%s'", $e->getMessage()));
383-
}
384-
if (null !== $code and $e->getCode() !== $code) {
385-
$this->fail(sprintf("Exception of $class expected to have code $code, but actual code was %s", $e->getCode()));
386-
}
387-
$this->assertTrue(true); // increment assertion counter
370+
$msg = $exception->getMessage();
371+
$code = $exception->getCode();
372+
} else {
373+
$class = $exception;
374+
}
375+
try {
376+
$callback();
377+
} catch (\Exception $e) {
378+
if (!$e instanceof $class) {
379+
$this->fail(sprintf("Exception of class $class expected to be thrown, but %s caught", get_class($e)));
380+
}
381+
if (null !== $msg and $e->getMessage() !== $msg) {
382+
$this->fail(sprintf(
383+
"Exception of $class expected to be '$msg', but actual message was '%s'",
384+
$e->getMessage()
385+
));
386+
}
387+
if (null !== $code and $e->getCode() !== $code) {
388+
$this->fail(sprintf(
389+
"Exception of $class expected to have code $code, but actual code was %s",
390+
$e->getCode()
391+
));
392+
}
393+
$this->assertTrue(true); // increment assertion counter
388394
return;
389-
}
390-
$this->fail("Expected exception to be thrown, but nothing was caught");
391-
}
395+
}
396+
$this->fail("Expected exception to be thrown, but nothing was caught");
397+
}
392398
}

tests/unit/Codeception/Module/AssertsTest.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ class AssertsTest extends PHPUnit_Framework_TestCase
44
public function testAsserts()
55
{
66
$module = new \Codeception\Module\Asserts(make_container());
7-
$module->assertEquals(1,1);
8-
$module->assertContains(1,[1,2]);
9-
$module->assertSame(1,1);
7+
$module->assertEquals(1, 1);
8+
$module->assertContains(1, [1, 2]);
9+
$module->assertSame(1, 1);
1010
$module->assertNotSame(1, '1');
11-
$module->assertRegExp('/^[\d]$/','1');
12-
$module->assertNotRegExp('/^[a-z]$/','1');
11+
$module->assertRegExp('/^[\d]$/', '1');
12+
$module->assertNotRegExp('/^[a-z]$/', '1');
1313
$module->assertEmpty([]);
1414
$module->assertNotEmpty([1]);
1515
$module->assertNull(null);
@@ -28,9 +28,15 @@ public function testAsserts()
2828
public function testExceptions()
2929
{
3030
$module = new \Codeception\Module\Asserts(make_container());
31-
$module->expectException('Exception', function() { throw new Exception; });
32-
$module->expectException(new Exception('here'), function() { throw new Exception('here'); });
33-
$module->expectException(new Exception('here', 200), function() { throw new Exception('here', 200); });
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+
});
3440
}
3541

3642
/**
@@ -39,7 +45,8 @@ public function testExceptions()
3945
public function testExceptionFails()
4046
{
4147
$module = new \Codeception\Module\Asserts(make_container());
42-
$module->expectException(new Exception('here', 200), function() { throw new Exception('here', 2); });
48+
$module->expectException(new Exception('here', 200), function () {
49+
throw new Exception('here', 2);
50+
});
4351
}
44-
4552
}

0 commit comments

Comments
 (0)