Skip to content

Commit

Permalink
replace @ExpectedException* anotation (#1191)
Browse files Browse the repository at this point in the history
* remove @ExpectedException* annotation

* update tests
  • Loading branch information
mimmi20 authored and siad007 committed Nov 17, 2019
1 parent 56a86ba commit 6286617
Show file tree
Hide file tree
Showing 38 changed files with 244 additions and 252 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,10 @@ public function testUseDebugMode()
$this->condition->evaluate();
}

/**
* @expectedException BuildException
*/
public function testCanNotUseUnsupportedOperator()
{
$this->expectException(BuildException::class);

$this->condition->setOperator('<<<<');
}
}
4 changes: 3 additions & 1 deletion test/classes/phing/system/io/IniFileParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ public function testParseFile($data, $expected)

/**
* @covers IniFileParser::parseFile
* @expectedException IOException
*/
public function testParseFileCouldntOpenFile()
{
$phingFile = new PhingFile(uniqid('', true));

$this->expectException(IOException::class);

$this->parser->parseFile($phingFile);
}

Expand Down
8 changes: 6 additions & 2 deletions test/classes/phing/system/io/YamlFileParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,28 @@ public function tearDown(): void

/**
* @covers IniFileParser::parseFile
* @expectedException IOException
*/
public function testParseFileFileNotReadable()
{
$tmpFile = tempnam(FileUtils::getTempDir(), "test");
touch($tmpFile);
$file = new PhingFile($tmpFile);
unlink($tmpFile);

$this->expectException(IOException::class);

$this->objectToTest->parseFile($file);
}

/**
* @covers IniFileParser::parseFile
* @expectedException IOException
*/
public function testParseFileFileIncorrectYaml()
{
$file = new PhingFile($this->incorrectYamlFileStub);

$this->expectException(IOException::class);

$this->objectToTest->parseFile($file);
}

Expand Down
7 changes: 3 additions & 4 deletions test/classes/phing/system/lang/EventObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,11 @@ public function testEventObject()
$this->assertSame('EventObject[source=stdClass]', (string) $this->eventObject);
}

/**
* @expectedException Exception
* @expectedExceptionMessage Null source
*/
public function testEventObjectThrowsExceptionOnNull()
{
$this->expectException(Exception::class);
$this->expectExceptionMessage('Null source');

new EventObject(null);
}
}
38 changes: 24 additions & 14 deletions test/classes/phing/tasks/PropertyTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,19 @@ public function testPrefixSuccess()

public function testPrefixFailure()
{
try {
$this->executeTarget("prefix.fail");
} catch (BuildException $e) {
$this->assertContains("Prefix is only valid", $e->getMessage(), "Prefix allowed on non-resource/file load - ");
$this->expectException(BuildException::class);
$this->expectExceptionMessageRegExp('/Prefix is only valid/');

return;
}
$this->fail("Did not throw exception on invalid use of prefix");
// try {
// $this->executeTarget("prefix.fail");
// } catch (BuildException $e) {
// $this->assertContains("Prefix is only valid", $e->getMessage(), "Prefix allowed on non-resource/file load - ");
//
// return;
// }
// $this->fail("Did not throw exception on invalid use of prefix");

$this->executeTarget("prefix.fail");
}

public function testFilterChain()
Expand All @@ -83,14 +88,19 @@ public function circularDefinitionTargets()
*/
public function testCircularDefinitionDetection($target)
{
try {
$this->executeTarget($target);
} catch (BuildException $e) {
$this->assertContains("was circularly defined", $e->getMessage(), "Circular definition not detected - ");
$this->expectException(BuildException::class);
$this->expectExceptionMessageRegExp('/was circularly defined/');

// try {
// $this->executeTarget($target);
// } catch (BuildException $e) {
// $this->assertContains("was circularly defined", $e->getMessage(), "Circular definition not detected - ");
//
// return;
// }
// $this->fail("Did not throw exception on circular exception");

return;
}
$this->fail("Did not throw exception on circular exception");
$this->executeTarget($target);
}

public function testToString()
Expand Down
5 changes: 2 additions & 3 deletions test/classes/phing/tasks/TaskdefTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@ public function testNoClassname()
$this->expectBuildException("noClassname", "required argument not specified");
}

/**
* @expectedException BuildException
*/
public function testClassNotFound()
{
$this->expectException(BuildException::class);

try {
$this->executeTarget("classNotFound");
$this->fail(
Expand Down
5 changes: 2 additions & 3 deletions test/classes/phing/tasks/TypedefTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,10 @@ public function testNoClassname()
$this->expectBuildException("noClassname", "required argument not specified");
}

/**
* @expectedException BuildException
*/
public function testClassNotFound()
{
$this->expectException(BuildException::class);

try {
$this->executeTarget("classNotFound");
$this->fail(
Expand Down
5 changes: 3 additions & 2 deletions test/classes/phing/tasks/ext/GrowlNotifyTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,13 @@ public function setUp(): void
/**
* Test for required message attribute
*
* @expectedException BuildException
* @expectedExceptionMessage "message" attribute cannot be empty
* @return void
*/
public function testEmptyMessage()
{
$this->expectException(BuildException::class);
$this->expectExceptionMessage('"message" attribute cannot be empty');

$this->executeTarget(__FUNCTION__);
}

Expand Down
6 changes: 2 additions & 4 deletions test/classes/phing/tasks/ext/HTTP/BaseHttpTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,10 @@ protected function createMockAdapter(array $responses)
return $adapter;
}

/**
* @expectedException BuildException
* @expectedExceptionMessage Required attribute 'url' is missing
*/
public function testMissingUrl()
{
$this->expectException(BuildException::class);
$this->expectExceptionMessage('Required attribute \'url\' is missing');
$this->executeTarget('missingURL');
}
}
15 changes: 7 additions & 8 deletions test/classes/phing/tasks/ext/HTTP/HttpGetTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,14 @@ public function setUp(): void
$this->configureProject(PHING_TEST_BASE . "/etc/tasks/ext/http/httpget.xml");
}

/**
* @expectedException BuildException
* @expectedExceptionMessage Required attribute 'dir' is missing
*/
public function testMissingDir()
{
$this->expectException(BuildException::class);
$this->expectExceptionMessage('Required attribute \'dir\' is missing');

$this->executeTarget('missingDir');
}

/**
* @expectedException BuildException
* @expectedExceptionMessage Response from server: 404 Not Found
*/
public function testError404()
{
$this->copyTasksAddingCustomRequest(
Expand All @@ -57,6 +52,10 @@ public function testError404()
)
)
);

$this->expectException(BuildException::class);
$this->expectExceptionMessage('Response from server: 404 Not Found');

$this->executeTarget('recipient');
}

Expand Down
7 changes: 3 additions & 4 deletions test/classes/phing/tasks/ext/HTTP/HttpRequestTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,13 @@ public function testMatchesCodeRegexp()
$this->expectLog('recipient', 'The response status-code matched the provided regex.');
}

/**
* @expectedException BuildException
* @expectedExceptionMessage The received response body did not match the given regular expression
*/
public function testDoesntMatchRegexp()
{
$this->copyTasksAddingCustomRequest('doesNotMatchRegexp', 'recipient', $this->createRequestWithMockAdapter());

$this->expectException(BuildException::class);
$this->expectExceptionMessage('The received response body did not match the given regular expression');

$this->executeTarget('recipient');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ public function testExecutableCanBeSet(): void

/**
* @depends testItRun
* @expectedException BuildException
* @expectedExceptionMessage unknown command
*/
public function testTestInvalidCommandCausesBuildError(): void
{
$this->expectException(BuildException::class);
$this->expectExceptionMessage('unknown command');
$this->executeTarget("testInvalidCommand");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,13 @@ public function testItCanCreateHelpCommandBuilder(): void
$this->assertInstanceOf(PHPStanHelpCommandBuilder::class, $builder);
}

/**
* @expectedException BuildException
*/
public function testItThrowsExceptionWhenCommandIsUnknown(): void
{
$task = new PHPStanTask();
$task->setCommand('any unknown');

$this->expectException(BuildException::class);

$this->factory->createBuilder($task);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,13 @@ public function testItHandleBaseCommandParts(): void
$this->assertEquals($cmd, str_replace("\r", '', $task->getCommandline()->describeCommand()));
}

/**
* @expectedException BuildException
*/
public function testItFailsWhenExecutableNotSet(): void
{
$task = new PHPStanTask();
$task->setExecutable('');

$this->expectException(BuildException::class);

$this->builder->build($task);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,21 @@ public function tearDown(): void
$this->sassCleanUp(self::SASS_TEST_BASE, 'test.css');
}

/**
* @expectedException BuildException
* @expectedExceptionMessage Neither sass nor scssphp are to be used.
*/
public function testNothing(): void
{
$this->expectException(BuildException::class);
$this->expectExceptionMessage('Neither sass nor scssphp are to be used.');

$this->executeTarget("nothing");
}

/**
* @expectedException BuildException
* @expectedExceptionMessage Neither sass nor scssphp are to be used.
*/
public function testSetStyleToUnrecognised(): void
{
$this->expectException(BuildException::class);
$this->expectExceptionMessage('Neither sass nor scssphp are to be used.');

$this->executeTarget("testSettingUnrecognisedStyle");

$this->assertInLogs('Style compacted ignored', Project::MSG_INFO);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ public function testItNotProducesAnyCompiledOutputWhenNoInput(): void
$this->assertFileNotExists(self::SASS_TEST_BASE . 'test.css');
}

/**
* @expectedException BuildException
*/
public function testItThrowsExceptionWhenFailOnErrorIsSet(): void
{
$this->compiler->compile(
Expand All @@ -79,6 +76,8 @@ public function testItThrowsExceptionWhenFailOnErrorIsSet(): void
true
);

$this->expectException(BuildException::class);

$this->assertFileNotExists(self::SASS_TEST_BASE . 'test.css');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,10 @@ public function testItNotProducesAnyCompiledOutputWhenNoInput(): void
$this->assertFileNotExists(self::SASS_TEST_BASE . 'test.css');
}

/**
* @expectedException BuildException
*/
public function testItThrowsExceptionWhenFailOnErrorIsSet(): void
{
$this->expectException(BuildException::class);

$this->compiler->compile(
self::SASS_TEST_BASE . 'non-existing.sass',
self::SASS_TEST_BASE . 'test.css',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@
class SassTaskCompilerFactoryTest extends TestCase
{

/**
* @expectedException BuildException
* @expectedExceptionMessage Neither sass nor scssphp are to be used.
*/
public function testItFailsWhenNoCompilerIsSet(): void
{
$sassTask = new SassTask();
Expand All @@ -36,6 +32,9 @@ public function testItFailsWhenNoCompilerIsSet(): void
$fileSystem = new FileSystemWhichStub(true);
$factory = new SassTaskCompilerFactory($fileSystem);

$this->expectException(BuildException::class);
$this->expectExceptionMessage('Neither sass nor scssphp are to be used.');

$factory->prepareCompiler($sassTask);
}

Expand Down Expand Up @@ -65,10 +64,6 @@ public function testItPrefersSassCompiler(): void
$this->assertInstanceOf(SassCompiler::class, $compiler);
}

/**
* @expectedException BuildException
* @expectedExceptionMessage sass not found. Install sass.
*/
public function testItFailsWhenSassExecutableNotFound(): void
{
$sassTask = new SassTask();
Expand All @@ -78,6 +73,9 @@ public function testItFailsWhenSassExecutableNotFound(): void
$fileSystem = new FileSystemWhichStub(false);
$factory = new SassTaskCompilerFactory($fileSystem);

$this->expectException(BuildException::class);
$this->expectExceptionMessage('sass not found. Install sass.');

$factory->prepareCompiler($sassTask);
}
}
Loading

0 comments on commit 6286617

Please sign in to comment.