Skip to content

Commit

Permalink
Merge pull request #54 from OndraM/fix/codestyle
Browse files Browse the repository at this point in the history
Codestyle improvements
  • Loading branch information
OndraM committed Mar 15, 2016
2 parents 96e0295 + 1108e97 commit 7e3edb1
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 50 deletions.
4 changes: 2 additions & 2 deletions src-tests/Process/ProcessWrapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ public function testShouldFailIfWrongProcessStatusGiven()

$this->setExpectedException(
InvalidArgumentException::class,
'Value "Foo" is not an element of the valid values: prepared, queued, done'
'Value "WrongStatus" is not an element of the valid values: prepared, queued, done'
);
$wrapper->setStatus('Foo', 'WrongStatus');
$wrapper->setStatus('WrongStatus');
}

public function testShouldPublishProcessStatusWhenStatusWasSet()
Expand Down
21 changes: 10 additions & 11 deletions src-tests/Publisher/XmlPublisherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function setUp()
ConfigHelper::setEnvironmentVariables($configValues);
ConfigHelper::unsetConfigInstance();

$this->publisher = new XmlPublisher(null, null, null);
$this->publisher = new XmlPublisher();
}

public static function tearDownAfterClass()
Expand Down Expand Up @@ -95,8 +95,7 @@ public function testShouldAddTestResultToEmptyFile()
$this->publisher->publishResult('testCaseNameFoo', 'testNameBar', 'started');

/** @var \SimpleXMLElement $xml */
$fullXml = simplexml_load_file($fileName);
$xml = $fullXml[0];
$xml = simplexml_load_file($fileName);

$this->assertInstanceOf(\SimpleXMLElement::class, $xml->testcase);
$this->assertEquals('testCaseNameFoo', $xml->testcase['name']);
Expand All @@ -112,7 +111,7 @@ public function testShouldAddTestResultToEmptyFile()
$startDate = (string) $xml->testcase->test['start']; // convert to string so it could be serialized by PHPUnit
$this->assertEmpty($xml->testcase->test['end']);

return [$fileName, $fullXml->asXML(), $startDate];
return [$fileName, $xml->asXML(), $startDate];
}

/**
Expand All @@ -132,7 +131,7 @@ public function testShouldUpdateTestStatusWhenTestIsDone($params)
$this->publisher->publishResult('testCaseNameFoo', 'testNameBar', 'done', 'passed');

/** @var \SimpleXMLElement $xml */
$xml = simplexml_load_file($fileName)[0];
$xml = simplexml_load_file($fileName);

// still only one test result is present
$this->assertInstanceOf(\SimpleXMLElement::class, $xml->testcase->test);
Expand All @@ -157,7 +156,7 @@ public function testShouldAddTestcaseResultToEmptyFile()
$this->publisher->publishResults('testCaseNameFoo', 'queued');

/** @var \SimpleXMLElement $xml */
$xml = simplexml_load_file($fileName)[0];
$xml = simplexml_load_file($fileName);

$this->assertInstanceOf(\SimpleXMLElement::class, $xml->testcase);
$this->assertEquals('testCaseNameFoo', $xml->testcase['name']);
Expand Down Expand Up @@ -187,7 +186,7 @@ public function testShouldUpdateTestcaseStatusWhenDone($params)
);

/** @var \SimpleXMLElement $xml */
$xml = simplexml_load_file($fileName)[0];
$xml = simplexml_load_file($fileName);

$this->assertInstanceOf(\SimpleXMLElement::class, $xml->testcase);
$this->assertEquals('testCaseNameFoo', $xml->testcase['name']);
Expand All @@ -208,7 +207,7 @@ public function testShouldFailIfGivenDirectoryDoesNotExists()
ConfigHelper::setEnvironmentVariables($configValues);
ConfigHelper::unsetConfigInstance();

$publisher = new XmlPublisher(null, null, null);
$publisher = new XmlPublisher();
$publisher->publishResult('testCaseNameFoo', 'testNameBar', 'started');
}

Expand All @@ -223,7 +222,7 @@ public function testShouldNotOverwriteTestsWithSameName()
$this->publisher->publishResult('testCaseNameBar', 'testFoo', 'done', XmlPublisher::TEST_RESULT_PASSED);

/** @var \SimpleXMLElement $xml */
$xml = simplexml_load_file($fileName)[0];
$xml = simplexml_load_file($fileName);

$tests = $xml->xpath('//test[@name="testFoo"]');

Expand All @@ -246,7 +245,7 @@ public function testShouldProperlyHandleTestsWithDataProvider($testCaseName, $te
$this->publisher->publishResult($testCaseName, $testName, XmlPublisher::TEST_STATUS_STARTED);

/** @var \SimpleXMLElement $xml */
$xml = simplexml_load_file($fileName)[0];
$xml = simplexml_load_file($fileName);
$this->assertInstanceOf(\SimpleXMLElement::class, $xml->testcase);
$this->assertEquals(1, count($xml->testcase));
$this->assertEquals($testCaseName, $xml->testcase['name']);
Expand All @@ -264,7 +263,7 @@ public function testShouldProperlyHandleTestsWithDataProvider($testCaseName, $te
);

/** @var \SimpleXMLElement $xml */
$xml = simplexml_load_file($fileName)[0];
$xml = simplexml_load_file($fileName);
$this->assertInstanceOf(\SimpleXMLElement::class, $xml->testcase);
$this->assertEquals(1, count($xml->testcase));
$this->assertEquals($testCaseName, $xml->testcase['name']);
Expand Down
4 changes: 2 additions & 2 deletions src/Component/Legacy.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,12 @@ public function loadWithName($legacyName)
/**
* Converts legacy value to string that can be printed (e.g. in log)
* calls __toString on the object if it's defined otherwise print_r()
* @param $obj
* @param mixed $obj
* @return string
*/
private function getPrintableValue($obj)
{
if (method_exists($obj, '__toString')) {
if (is_object($obj) && method_exists($obj, '__toString')) {
return $obj;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Component/TestUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function getFixturePath($fixture)
*/
public static function sleep($seconds)
{
$fullSecond = floor($seconds);
$fullSecond = (int) floor($seconds);
$microseconds = fmod($seconds, 1) * 1000000000;

time_nanosleep($fullSecond, $microseconds);
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Command/RunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ protected function getSeleniumAdapter()
protected function getProcessSetCreator(InputInterface $input, OutputInterface $output)
{
if (!$this->processSetCreator) {
$xmlPublisher = new XmlPublisher($input->getArgument(self::ARGUMENT_ENVIRONMENT), null, null);
$xmlPublisher = new XmlPublisher();
$xmlPublisher->setFileDir($input->getOption(self::OPTION_LOGS_DIR));
$xmlPublisher->clean();

Expand Down
2 changes: 1 addition & 1 deletion src/Console/EventListener/ListenerInstantiator.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function instantiate(EventDispatcher $dispatcher, $dir)
&& !$r->isAbstract()
) {
/** @var EventSubscriberInterface $listenerInstance */
$listenerInstance = $r->newInstance();
$listenerInstance = $r->newInstanceWithoutConstructor();
$dispatcher->addSubscriber($listenerInstance);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Process/ProcessWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class ProcessWrapper
private $status;
/** @var string */
private $result;
/** @var string */
/** @var int */
private $finishedTime;


Expand Down Expand Up @@ -178,7 +178,7 @@ public function getResult()
}

/**
* @return string
* @return int
*/
public function getFinishedTime()
{
Expand Down
19 changes: 0 additions & 19 deletions src/Publisher/AbstractPublisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,6 @@ abstract class AbstractPublisher
\PHPUnit_Runner_BaseTestRunner::STATUS_ERROR => self::TEST_RESULT_BROKEN,
];

/** @var string */
protected $environment;

/** @var string */
protected $jobName;

/** @var int */
protected $buildNumber;

/** @var bool */
protected $debug = false;

/**
* @param string $environment
* @param string $jobName
* @param int $buildNumber
*/
abstract public function __construct($environment, $jobName, $buildNumber);

/**
* Publish testcase result
*
Expand Down
11 changes: 0 additions & 11 deletions src/Publisher/XmlPublisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,6 @@ class XmlPublisher extends AbstractPublisher
/** @var resource */
protected $fileHandle;

/**
* Create the publisher.
*
* @param string $environment
* @param string $jobName
* @param int $buildNumber
*/
public function __construct($environment, $jobName, $buildNumber)
{
}

/**
* Set directory where results file should be stored. Usable when config object is not available (when
* not called from PHPUnit testcase but from Command). If the file dir is not set, the value from Config object
Expand Down

0 comments on commit 7e3edb1

Please sign in to comment.