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 reference inheritance test #1270

Merged
merged 1 commit into from
Feb 16, 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
108 changes: 108 additions & 0 deletions test/classes/phing/tasks/condition/PhingTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,112 @@ public function testBasedirTripleCall(): void
$dir2 = $this->getProject()->resolveFile("phing");
$this->baseDirs('tripleCall', [$dir1->getAbsolutePath(), $dir2->getAbsolutePath(), $dir1->getAbsolutePath()]);
}

public function testReferenceInheritance(): void
{
$p = new Path($this->getProject(), 'test-path');
$this->getProject()->addReference('path', $p);
$this->getProject()->addReference('no-override', $p);
$this->reference('testInherit', ['path', 'path'], [true, true], $p);
$this->reference('testInherit', ['no-override', 'no-override'], [true, false], $p);
$this->reference('testInherit', ['no-override', 'no-override'], [false, false], null);
}

protected function reference(string $target, array $keys, array $expect, $value): void
{
$rc = new class ($keys, $expect, $value) implements BuildListener {
private $keys;
private $expectSame;
private $value;
private $calls = 0;
private $error;

public function __construct(array $keys, array $expectSame, $value)
{
$this->keys = $keys;
$this->expectSame = $expectSame;
$this->value = $value;
}

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 {
$msg = "Call " . $this->calls . " refid=\'" . $this->keys[$this->calls] . "\'";
if ($this->value === null) {
$o = $event->getProject()->getReference($this->keys[$this->calls]);
if ($this->expectSame[$this->calls++]) {
PhingTaskTest::assertNull($o, $msg);
} else {
PhingTaskTest::assertNotNull($o, $msg);
}
} else {
// a rather convoluted equals() test
/** @var Path $expect */
$expect = $this->value;
$received = $event->getProject()->getReference($this->keys[$this->calls]);
$shouldBeEqual = $this->expectSame[$this->calls++];
if ($received === null) {
PhingTaskTest::assertFalse($shouldBeEqual, $msg);
} else {
$l1 = $expect->listPaths();
$l2 = $received->listPaths();
if (count($l1) === count($l2)) {
for ($i = 0, $iMax = count($l1); $i < $iMax; $i++) {
if ($l1[$i] !== $l2[$i]) {
PhingTaskTest::assertFalse($shouldBeEqual, $msg);
}
}
PhingTaskTest::assertTrue($shouldBeEqual, $msg);
} else {
PhingTaskTest::assertFalse($shouldBeEqual, $msg);
}
}
}
} catch (\Throwable $e) {
$this->error = $e;
}
}
}

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