Skip to content

Commit 398f8f4

Browse files
MAXakaWIZARDDavertMik
authored andcommitted
PSR-2 compliance (#3105)
* Add composer.lock to .gitignore * Put direct link to coding standards description * Fix spacing * Fix code style for ext and symfony-shim * Fix PSR2 compliance issues * Fix PSR2 compliance issues * Add generated test files to gitginore * Fix PSR2 compliance issues in tests * Get rid of long code lines in tests to comply PSR2 * Get rid of long code lines to comply PSR2 * Add code style rule set * Fix wrong indentation * Improve code style
1 parent 218a8eb commit 398f8f4

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
@@ -377,32 +377,38 @@ public function fail($message)
377377
* @param $callback
378378
*/
379379
public function expectException($exception, $callback)
380-
{
381-
$code = null;
382-
$msg = null;
383-
if (is_object($exception)) {
384-
/** @var $exception \Exception **/
380+
{
381+
$code = null;
382+
$msg = null;
383+
if (is_object($exception)) {
384+
/** @var $exception \Exception **/
385385
$class = get_class($exception);
386-
$msg = $exception->getMessage();
387-
$code = $exception->getCode();
388-
} else {
389-
$class = $exception;
390-
}
391-
try {
392-
$callback();
393-
} catch (\Exception $e) {
394-
if (!$e instanceof $class) {
395-
$this->fail(sprintf("Exception of class $class expected to be thrown, but %s caught", get_class($e)));
396-
}
397-
if (null !== $msg and $e->getMessage() !== $msg) {
398-
$this->fail(sprintf("Exception of $class expected to be '$msg', but actual message was '%s'", $e->getMessage()));
399-
}
400-
if (null !== $code and $e->getCode() !== $code) {
401-
$this->fail(sprintf("Exception of $class expected to have code $code, but actual code was %s", $e->getCode()));
402-
}
403-
$this->assertTrue(true); // increment assertion counter
386+
$msg = $exception->getMessage();
387+
$code = $exception->getCode();
388+
} else {
389+
$class = $exception;
390+
}
391+
try {
392+
$callback();
393+
} catch (\Exception $e) {
394+
if (!$e instanceof $class) {
395+
$this->fail(sprintf("Exception of class $class expected to be thrown, but %s caught", get_class($e)));
396+
}
397+
if (null !== $msg and $e->getMessage() !== $msg) {
398+
$this->fail(sprintf(
399+
"Exception of $class expected to be '$msg', but actual message was '%s'",
400+
$e->getMessage()
401+
));
402+
}
403+
if (null !== $code and $e->getCode() !== $code) {
404+
$this->fail(sprintf(
405+
"Exception of $class expected to have code $code, but actual code was %s",
406+
$e->getCode()
407+
));
408+
}
409+
$this->assertTrue(true); // increment assertion counter
404410
return;
405-
}
406-
$this->fail("Expected exception to be thrown, but nothing was caught");
407-
}
411+
}
412+
$this->fail("Expected exception to be thrown, but nothing was caught");
413+
}
408414
}

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)