Skip to content

Commit

Permalink
Clean up #1358.
Browse files Browse the repository at this point in the history
  • Loading branch information
whatthejeff committed Jul 27, 2014
1 parent 64efc1d commit c85fcdc
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 55 deletions.
8 changes: 4 additions & 4 deletions src/Framework/Constraint/ExceptionMessageRegExp.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* @copyright 2001-2014 Sebastian Bergmann <[email protected]>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 3.6.6
* @since File available since Release 4.3
*/

/**
Expand All @@ -52,7 +52,7 @@
* @copyright 2001-2014 Sebastian Bergmann <[email protected]>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since Class available since Release 4.0.20
* @since Class available since Release 4.3
*/
class PHPUnit_Framework_Constraint_ExceptionMessageRegExp extends PHPUnit_Framework_Constraint
{
Expand Down Expand Up @@ -80,10 +80,10 @@ public function __construct($expected)
protected function matches($other)
{
$match = PHPUnit_Util_Regex::pregMatchSafe($this->expectedMessageRegExp, $other->getMessage());

if(false === $match) {
throw new PHPUnit_Framework_Exception (
"Invalid expected exception message regex given: '{$this->expectedMessageRegExp}'"
"Invalid expected exception message regex given: '{$this->expectedMessageRegExp}'"
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Framework/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ protected function setExpectedExceptionFromAnnotation()
$expectedException['code']
);

if(isset($expectedException['message_regex']) && ! empty($expectedException['message_regex'])) {
if(!empty($expectedException['message_regex'])) {
$this->setExpectedExceptionRegExp(
$expectedException['class'],
$expectedException['message_regex'],
Expand Down
22 changes: 11 additions & 11 deletions src/Util/Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,19 @@ public static function getLinesToBeUsed($className, $methodName)
private static function getLinesToBeCoveredOrUsed($className, $methodName, $mode)
{
$annotations = self::parseTestMethodAnnotations(
$className, $methodName
$className, $methodName
);

$classShortcut = null;

if (!empty($annotations['class'][$mode . 'DefaultClass'])) {
if (count($annotations['class'][$mode . 'DefaultClass']) > 1) {
throw new PHPUnit_Framework_CodeCoverageException(
sprintf(
'More than one @%sClass annotation in class or interface "%s".',
$mode,
$className
)
sprintf(
'More than one @%sClass annotation in class or interface "%s".',
$mode,
$className
)
);
}

Expand All @@ -190,8 +190,8 @@ private static function getLinesToBeCoveredOrUsed($className, $methodName, $mode
$element = preg_replace('/[\s()]+$/', '', $element);

$codeList = array_merge(
$codeList,
self::resolveElementToReflectionObjects($element)
$codeList,
self::resolveElementToReflectionObjects($element)
);
}

Expand Down Expand Up @@ -322,21 +322,21 @@ public static function getExpectedException($className, $methodName)
$message = trim($matches[2]);
} elseif (isset($annotations['method']['expectedExceptionMessage'])) {
$message = self::parseAnnotationContent(
$annotations['method']['expectedExceptionMessage'][0]
$annotations['method']['expectedExceptionMessage'][0]
);
}

if (isset($annotations['method']['expectedExceptionMessageRegExp'])) {
$messageRegExp = self::parseAnnotationContent(
$annotations['method']['expectedExceptionMessageRegExp'][0]
$annotations['method']['expectedExceptionMessageRegExp'][0]
);
}

if (isset($matches[3])) {
$code = $matches[3];
} elseif (isset($annotations['method']['expectedExceptionCode'])) {
$code = self::parseAnnotationContent(
$annotations['method']['expectedExceptionCode'][0]
$annotations['method']['expectedExceptionCode'][0]
);
}

Expand Down
6 changes: 3 additions & 3 deletions tests/Framework/Constraint/ExceptionMessageRegExpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* @copyright 2001-2014 Sebastian Bergmann <[email protected]>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 3.7.30
* @since File available since Release 4.3
*/

/**
Expand All @@ -51,7 +51,7 @@
* @copyright 2001-2014 Sebastian Bergmann <[email protected]>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since Class available since Release 4.0.20
* @since Class available since Release 4.3
* @covers PHPUnit_Framework_Constraint_ExceptionMessageRegExp
*/
class ExceptionMessageRegExpTest extends PHPUnit_Framework_TestCase
Expand Down Expand Up @@ -88,7 +88,7 @@ public function testMessageXdebugScreamCompatibility()
}

/**
* @coversNothing
* @coversNothing
* @expectedException \Exception variadic
* @expectedExceptionMessageRegExp /^A variadic \w+ message/
*/
Expand Down
72 changes: 36 additions & 36 deletions tests/Util/TestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,34 +119,34 @@ public function testGetExpectedException()
);

$this->assertSame(
array('class' => 'Class', 'code' => My\Space\ExceptionNamespaceTest::ERROR_CODE, 'message' => My\Space\ExceptionNamespaceTest::ERROR_MESSAGE, 'message_regex' => ''),
PHPUnit_Util_Test::getExpectedException('My\Space\ExceptionNamespaceTest', 'testConstants')
array('class' => 'Class', 'code' => My\Space\ExceptionNamespaceTest::ERROR_CODE, 'message' => My\Space\ExceptionNamespaceTest::ERROR_MESSAGE, 'message_regex' => ''),
PHPUnit_Util_Test::getExpectedException('My\Space\ExceptionNamespaceTest', 'testConstants')
);

$this->assertSame(
array('class' => 'Class', 'code' => 1234, 'message' => 'Message', 'message_regex' => '#regex#'),
PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testWithRegexMessage')
array('class' => 'Class', 'code' => 1234, 'message' => 'Message', 'message_regex' => '#regex#'),
PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testWithRegexMessage')
);

$this->assertSame(
array('class' => 'Class', 'code' => 1234, 'message' => 'Message', 'message_regex' => '#regex#'),
PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testWithRegexMessageFromClassConstant')
);
array('class' => 'Class', 'code' => 1234, 'message' => 'Message', 'message_regex' => '#regex#'),
PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testWithRegexMessageFromClassConstant')
);

$this->assertSame(
array('class' => 'Class', 'code' => 1234, 'message' => 'Message', 'message_regex' => 'ExceptionTest::UNKNOWN_MESSAGE_REGEX_CONSTANT'),
PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testWithUnknowRegexMessageFromClassConstant')
);
array('class' => 'Class', 'code' => 1234, 'message' => 'Message', 'message_regex' => 'ExceptionTest::UNKNOWN_MESSAGE_REGEX_CONSTANT'),
PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testWithUnknowRegexMessageFromClassConstant')
);

// Ensure the Class::CONST expression is only evaluated when the constant really exists
$this->assertSame(
array('class' => 'Class', 'code' => 'ExceptionTest::UNKNOWN_CODE_CONSTANT', 'message' => 'ExceptionTest::UNKNOWN_MESSAGE_CONSTANT', 'message_regex' => ''),
PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testUnknownConstants')
array('class' => 'Class', 'code' => 'ExceptionTest::UNKNOWN_CODE_CONSTANT', 'message' => 'ExceptionTest::UNKNOWN_MESSAGE_CONSTANT', 'message_regex' => ''),
PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testUnknownConstants')
);

$this->assertSame(
array('class' => 'Class', 'code' => 'My\Space\ExceptionNamespaceTest::UNKNOWN_CODE_CONSTANT', 'message' => 'My\Space\ExceptionNamespaceTest::UNKNOWN_MESSAGE_CONSTANT', 'message_regex' => ''),
PHPUnit_Util_Test::getExpectedException('My\Space\ExceptionNamespaceTest', 'testUnknownConstants')
array('class' => 'Class', 'code' => 'My\Space\ExceptionNamespaceTest::UNKNOWN_CODE_CONSTANT', 'message' => 'My\Space\ExceptionNamespaceTest::UNKNOWN_MESSAGE_CONSTANT', 'message_regex' => ''),
PHPUnit_Util_Test::getExpectedException('My\Space\ExceptionNamespaceTest', 'testUnknownConstants')
);
}

Expand Down Expand Up @@ -177,27 +177,27 @@ public function requirementsProvider()
array('testTen', array('extensions' => array('testExt'))),
array('testEleven', array('OS' => '/Linux/i')),
array(
'testSpace',
array(
'extensions' => array('spl'),
'OS' => '/.*/i'
)
'testSpace',
array(
'extensions' => array('spl'),
'OS' => '/.*/i'
)
),
array(
'testAllPossibleRequirements',
array(
'PHP' => '99-dev',
'PHPUnit' => '9-dev',
'OS' => '/DOESNOTEXIST/i',
'functions' => array(
'testFuncOne',
'testFuncTwo',
),
'extensions' => array(
'testExtOne',
'testExtTwo',
)
'testAllPossibleRequirements',
array(
'PHP' => '99-dev',
'PHPUnit' => '9-dev',
'OS' => '/DOESNOTEXIST/i',
'functions' => array(
'testFuncOne',
'testFuncTwo',
),
'extensions' => array(
'testExtOne',
'testExtTwo',
)
)
)
);
}
Expand All @@ -212,12 +212,12 @@ public function testGetRequirementsMergesClassAndMethodDocBlocks()
'PHPUnit' => '3.7',
'OS' => '/WINNT/i',
'functions' => array(
'testFuncClass',
'testFuncMethod',
'testFuncClass',
'testFuncMethod',
),
'extensions' => array(
'testExtClass',
'testExtMethod',
'testExtClass',
'testExtMethod',
)
);

Expand Down

8 comments on commit c85fcdc

@marcioAlmada
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was the indentation fixed automatically? If yes, what tool are you using? So I can apply it for the next PR :D

@whatthejeff
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcioAlmada I did it manually. Maybe @sebastianbergmann has a tool to automate it. We just use two spaces to indent inside a single statement. Took me a while to get used to it, but now it's pretty easy to spot. Not quite sure about the origins of this style, though. Maybe we should consider changing it since it's a little non-standard these days.

@sebastianbergmann
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Components that are factored out of PHPUnit (Diff, Exporter, ...) (should) already use PSR-2. At some point PHPUnit itself should be migrated to PSR-2, too.

@whatthejeff
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sebastianbergmann Sounds good. Maybe once we factor out the remaining components :)

@sebastianbergmann
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't wait for phpunit/phpunit to be just a meta package that pulls in the framework, its dependencies, and a test runner ;-)

@whatthejeff
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sebastianbergmann I'm hoping to find the time to work on the assertions / constraints components next weekend.

@sebastianbergmann
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome; would be great to get it into 4.3.

@marcioAlmada
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, noted. I've been using php-cs-fixer to automate this kind of task for months, almost without problems.

Please sign in to comment.