Skip to content

Commit

Permalink
fixed expectExceptionMessage and expectExceptionCode not working whit…
Browse files Browse the repository at this point in the history
…hout setExpectedException
  • Loading branch information
Jean Carlo Machado authored and sebastianbergmann committed Jan 25, 2017
1 parent e934314 commit e208250
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Framework/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,10 @@ public function expectException($exception)
*/
public function expectExceptionCode($code)
{
if (!$this->expectedException) {
$this->expectedException = \Exception::class;
}

if (!is_int($code) && !is_string($code)) {
throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'integer or string');
}
Expand All @@ -629,6 +633,10 @@ public function expectExceptionCode($code)
*/
public function expectExceptionMessage($message)
{
if (!$this->expectedException) {
$this->expectedException = \Exception::class;
}

if (!is_string($message)) {
throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
}
Expand Down
21 changes: 21 additions & 0 deletions tests/Regression/GitHub/2299/Issue2299Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/**
* @author Jean Carlo Machado <contato@jeancarlomachado.com.br>
*/
class Test extends PHPUnit_Framework_TestCase
{
public function testOne()
{
$this->expectExceptionMessage('message');

throw new Exception('message');
}

public function testTwo()
{
$this->expectExceptionCode(123);

throw new Exception('message', 123);
}
}

0 comments on commit e208250

Please sign in to comment.