Skip to content

Commit

Permalink
Removed returns on void
Browse files Browse the repository at this point in the history
  • Loading branch information
siad007 committed Apr 24, 2021
1 parent d579caf commit e665d17
Showing 1 changed file with 79 additions and 79 deletions.
158 changes: 79 additions & 79 deletions tests/Phing/Task/System/ApplyTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,81 @@ public function testPropertySetOs(): void
$this->assertAttributeIsSetTo('os', 'linux');
}

/**
* @param string $property
* @param mixed $value
* @param null $propertyName
* @throws ReflectionException
*/
protected function assertAttributeIsSetTo(string $property, $value, $propertyName = null): void
{
$task = $this->getConfiguredTask('testPropertySet' . ucfirst($property), ApplyTask::class);

$propertyName = $propertyName ?? $property;
$rprop = new ReflectionProperty(ApplyTask::class, $propertyName);
$rprop->setAccessible(true);
$this->assertEquals($value, $rprop->getValue($task));
}

/**
* @param string $target
* @param string $task
*
* @return Task
* @throws Exception
*/
protected function getConfiguredTask(string $target, string $task): Task
{
$target = $this->getTargetByName($target);
$task = $this->getTaskFromTarget($target, $task);
$task->maybeConfigure();

if ($task instanceof UnknownElement) {
return $task->getRuntimeConfigurableWrapper()->getProxy();
}

return $task;
}

/**
* @param string $name
*
* @return Target
* @throws Exception
*/
protected function getTargetByName(string $name): Target
{
foreach ($this->project->getTargets() as $target) {
if ($target->getName() == $name) {
return $target;
}
}

throw new Exception(sprintf('Target "%s" not found', $name));
}

/**
* @param $target
* @param string $taskName
* @param int $pos
*
* @return Task
* @throws Exception
*/
protected function getTaskFromTarget($target, string $taskName, $pos = 0): Task
{
$rchildren = new ReflectionProperty(get_class($target), 'children');
$rchildren->setAccessible(true);
$n = -1;
foreach ($rchildren->getValue($target) as $child) {
if ($child instanceof Task && ++$n == $pos) {
return $child;
}
}

throw new Exception(sprintf('%s #%d not found in task', $taskName, $pos));
}

/**
* Tests the dir configuration setting.
*/
Expand Down Expand Up @@ -224,7 +299,7 @@ public function testFailOnNonExistingDir(): void
. 'existent' . DIRECTORY_SEPARATOR
. 'dir';

return $this->expectBuildExceptionContaining(
$this->expectBuildExceptionContaining(
__FUNCTION__,
__FUNCTION__,
"'{$nonExistentDir}' is not a valid directory"
Expand Down Expand Up @@ -260,7 +335,7 @@ public function testCheckreturnTrue(): void
*/
public function testCheckreturnFalse(): void
{
return $this->expectBuildExceptionContaining(__FUNCTION__, __FUNCTION__, 'Task exited with code (1)');
$this->expectBuildExceptionContaining(__FUNCTION__, __FUNCTION__, 'Task exited with code (1)');
}

/**
Expand Down Expand Up @@ -402,6 +477,8 @@ public function testRelativeSourceFilenames(): void
$this->assertNotInLogs('/etc/');
}

// H E L P E R M E T H O D S

/**
* Tests the source filename addition functionality.
*
Expand Down Expand Up @@ -460,81 +537,4 @@ public function testMapperSupport(): void
}
$this->assertContains('Applied echo to 4 files and 0 directories.', $messages);
}

// H E L P E R M E T H O D S

/**
* @param string $name
*
* @return Target
* @throws Exception
*/
protected function getTargetByName(string $name): Target
{
foreach ($this->project->getTargets() as $target) {
if ($target->getName() == $name) {
return $target;
}
}

throw new Exception(sprintf('Target "%s" not found', $name));
}

/**
* @param $target
* @param string $taskName
* @param int $pos
*
* @return Task
* @throws Exception
*/
protected function getTaskFromTarget($target, string $taskName, $pos = 0): Task
{
$rchildren = new ReflectionProperty(get_class($target), 'children');
$rchildren->setAccessible(true);
$n = -1;
foreach ($rchildren->getValue($target) as $child) {
if ($child instanceof Task && ++$n == $pos) {
return $child;
}
}

throw new Exception(sprintf('%s #%d not found in task', $taskName, $pos));
}

/**
* @param string $target
* @param string $task
*
* @return Task
* @throws Exception
*/
protected function getConfiguredTask(string $target, string $task): Task
{
$target = $this->getTargetByName($target);
$task = $this->getTaskFromTarget($target, $task);
$task->maybeConfigure();

if ($task instanceof UnknownElement) {
return $task->getRuntimeConfigurableWrapper()->getProxy();
}

return $task;
}

/**
* @param string $property
* @param mixed $value
* @param null $propertyName
* @throws ReflectionException
*/
protected function assertAttributeIsSetTo(string $property, $value, $propertyName = null): void
{
$task = $this->getConfiguredTask('testPropertySet' . ucfirst($property), ApplyTask::class);

$propertyName = $propertyName ?? $property;
$rprop = new ReflectionProperty(ApplyTask::class, $propertyName);
$rprop->setAccessible(true);
$this->assertEquals($value, $rprop->getValue($task));
}
}

0 comments on commit e665d17

Please sign in to comment.