Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PhingTask] Added some more tests #1263

Merged
merged 1 commit into from
Feb 15, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions test/classes/phing/tasks/condition/PhingTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,85 @@ public function test6(): void
{
$this->getProject()->executeTarget(__FUNCTION__);
}

public function testExplicitBasedir1(): void
{
$dir1 = $this->getProject()->getBaseDir();
$dir2 = $this->getProject()->resolveFile("..");
$this->baseDirs('explicitBasedir1', [$dir1->getAbsolutePath(), $dir2->getAbsolutePath()]);
}

private function baseDirs(string $target, array $dirs): void
{
$bc = new class ($dirs) implements BuildListener {
private $expectedBasedirs;
private $calls = 0;
private $error;

public function __construct(array $dirs)
{
$this->expectedBasedirs = $dirs;
}

public function buildStarted(BuildEvent $event)
{
}

public function buildFinished(BuildEvent $event)
{
}

public function targetFinished(BuildEvent $event)
{
}

public function taskStarted(BuildEvent $event)
{
}

public function taskFinished(BuildEvent $event)
{
}

public function messageLogged(BuildEvent $event)
{
}

public function targetStarted(BuildEvent $event)
{
if ($event->getTarget()->getName() === '') {
return;
}
if ($this->error === null) {
try {
BuildFileTest::assertEquals(
$this->expectedBasedirs[$this->calls++],
$event->getProject()->getBaseDir()->getAbsolutePath()
);
} catch (AssertionError $e) {
$this->error = $e;
}
}
}

public function getError()
{
return $this->error;
}
};
$this->getProject()->addBuildListener($bc);
$this->executeTarget($target);
$ae = $bc->getError();
if ($ae !== null) {
throw $ae;
}
$this->getProject()->removeBuildListener($bc);
}

public function testExplicitBasedir2(): void
{
$dir1 = $this->getProject()->getBaseDir();
$dir2 = $this->getProject()->resolveFile("..");
$this->baseDirs('explicitBasedir2', [$dir1->getAbsolutePath(), $dir2->getAbsolutePath()]);
}
}