Skip to content

Commit

Permalink
Resolve various PHPStorm warnings
Browse files Browse the repository at this point in the history
These warnings can be seen by running Code Inspection via the Code -> Inspect Code menu item.

It was not possible to resolve all of the warnings, as some are intentional and there is no way to disable the inspection for the statement.
  • Loading branch information
Chekote committed Nov 12, 2017
1 parent bd771fb commit 6b3776f
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 48 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.idea/
!.idea/php.xml

/vendor/
docker/.env
11 changes: 8 additions & 3 deletions bin/behat
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ register_shutdown_function('fatalHandler');

define('BEHAT_BIN_PATH', __FILE__);

/**
* Includes the specified file if it exists.
*
* @param string $file the file to include.
* @return mixed the value that the file returns.
*/
function includeIfExists($file)
{
if (file_exists($file)) {
return include $file;
}
/** @noinspection PhpIncludeInspection no way to inspect a dynamic include */
return file_exists($file) ? include $file : false;
}

if (!$loader = includeIfExists(__DIR__.'/../vendor/autoload.php')) {
Expand Down
2 changes: 1 addition & 1 deletion bin/containers
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ else
fi

echo "Working on containers..."
docker-compose -p $PROJECT_NAME \
docker-compose -p ${PROJECT_NAME} \
-f "$ROOT"/docker/docker-compose.yml \
"$@"
6 changes: 6 additions & 0 deletions dictionary.dic
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
colspan
coords
getcsv
keypress
Kudryashov
Lazarecki
Medology
screenshot
Serdyuk
tbody
tfoot
thead
Expand Down
15 changes: 11 additions & 4 deletions src/Medology/Behat/Mink/FlexibleContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -638,9 +638,10 @@ public function deleteCookie($key)
* Attaches a local file to field with specified id|name|label|value. This is used when running behat and
* browser session in different containers.
*
* @When /^(?:|I )attach the local file "(?P<path>[^"]*)" to "(?P<field>(?:[^"]|\\")*)"$/
* @param string $field The file field to select the file with
* @param string $path The local path of the file
* @When /^(?:|I )attach the local file "(?P<path>[^"]*)" to "(?P<field>(?:[^"]|\\")*)"$/
* @param string $field The file field to select the file with
* @param string $path The local path of the file
* @throws UnsupportedDriverActionException if getWebDriverSession() is not supported by the current driver.
*/
public function addLocalFileToField($path, $field)
{
Expand All @@ -660,7 +661,13 @@ public function addLocalFileToField($path, $field)
$zip->addFile($path, basename($path));
$zip->close();

$remotePath = $this->getSession()->getDriver()->getWebDriverSession()->file([
$driver = $this->getSession()->getDriver();
if (!($driver instanceof Selenium2Driver)) {
throw new UnsupportedDriverActionException('getWebDriverSession() is not supported by %s', $driver);
}

/** @noinspection PhpUndefinedMethodInspection file() method annotation is missing from WebDriver\Session */
$remotePath = $driver->getWebDriverSession()->file([
'file' => base64_encode(file_get_contents($tempZip)),
]);

Expand Down
2 changes: 1 addition & 1 deletion src/Medology/Behat/Mink/JavaScriptContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Behat\Mink\Exception\ExpectationException;

/**
* {@inheritdoc}
* Provides functionality modifying and checking the Javascript environment in the browser.
*/
class JavaScriptContext implements Context
{
Expand Down
2 changes: 1 addition & 1 deletion src/Medology/Behat/ParallelWorker/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use RuntimeException;

/**
* A scenario filter which filters on individual scenarios and outlines. Usefull for separating tests onto multiple
* A scenario filter which filters on individual scenarios and outlines. Useful for separating tests onto multiple
* worker nodes.
*
* Based on the behat-partial-runner (http://github.com/m00t/behat-partial-runner) by Anton Serdyuk (m00t).
Expand Down
4 changes: 2 additions & 2 deletions src/Medology/Behat/TypeCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public function castStringToBool($string)
* Casts a Quoted string to a string.
*
* This is helpful for when you want to write a step definition that
* accepts values that look like other scalar types, such as ints or
* bools.
* accepts values that look like other scalar types, such as int or
* bool.
*
* For example, if you wrote your step definition as follows:
*
Expand Down
1 change: 1 addition & 0 deletions tests/Behat/DefaultMocks/MagicMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ public function __call($method, $arguments)

public function __toString()
{
return '';
}
}
64 changes: 41 additions & 23 deletions tests/Medology/Behat/ParallelWorker/FilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function testParallelWorkerFilter()
// message check
try {
new Filter(-10, 10);
$this->expectException(InvalidArgumentException::class);
self::setExpectedException(InvalidArgumentException::class);
} catch (Exception $e) {
$this->assertEquals('Received bad arguments for ($curNode, $totalNodes): (-10, 10).', $e->getMessage());
}
Expand All @@ -29,28 +29,28 @@ public function testParallelWorkerFilter()
**************************/
try {
new Filter(-1, 1);
$this->expectException(InvalidArgumentException::class);
self::setExpectedException(InvalidArgumentException::class);
} catch (Exception $e) {
$this->assertTrue($e instanceof InvalidArgumentException);
}

try {
new Filter(0, 0);
$this->expectException(InvalidArgumentException::class);
self::setExpectedException(InvalidArgumentException::class);
} catch (Exception $e) {
$this->assertTrue($e instanceof InvalidArgumentException);
}

try {
new Filter(-1, -1);
$this->expectException(InvalidArgumentException::class);
self::setExpectedException(InvalidArgumentException::class);
} catch (Exception $e) {
$this->assertTrue($e instanceof InvalidArgumentException);
}

try {
new Filter(2, 1);
$this->expectException(InvalidArgumentException::class);
self::setExpectedException(InvalidArgumentException::class);
} catch (Exception $e) {
$this->assertTrue($e instanceof InvalidArgumentException);
}
Expand Down Expand Up @@ -105,12 +105,14 @@ public function testFeatureFilterDefaults()
$this->assertEquals('Scenario#3', $scenarios[2]->getTitle());

$this->assertTrue($scenarios[2] instanceof OutlineNode);
$this->assertTrue($scenarios[2]->hasExamples());
/** @var OutlineNode $outline */
$outline = $scenarios[2];
$this->assertTrue($outline->hasExamples());
$this->assertEquals([
['action' => 'act#1', 'outcome' => 'out#1'],
['action' => 'act#2', 'outcome' => 'out#2'],
['action' => 'act#3', 'outcome' => 'out#3'],
], $scenarios[2]->getExampleTable()->getColumnsHash());
], $outline->getExampleTable()->getColumnsHash());

$this->assertEquals('Scenario#3 HD Remix', $scenarios[3]->getTitle());
}
Expand All @@ -132,11 +134,13 @@ public function testFeatureFilterNodes2()
$this->assertEquals('Scenario#3', $scenarios[1]->getTitle());

$this->assertTrue($scenarios[1] instanceof OutlineNode);
$this->assertTrue($scenarios[1]->hasExamples());
/** @var OutlineNode $outline */
$outline = $scenarios[1];
$this->assertTrue($outline->hasExamples());
$this->assertEquals([
['action' => 'act#1', 'outcome' => 'out#1'],
['action' => 'act#3', 'outcome' => 'out#3'],
], $scenarios[1]->getExampleTable()->getColumnsHash());
], $outline->getExampleTable()->getColumnsHash());

/*****************
* Node 2 *
Expand All @@ -150,10 +154,12 @@ public function testFeatureFilterNodes2()
$this->assertEquals('Scenario#3', $scenarios[1]->getTitle());

$this->assertTrue($scenarios[1] instanceof OutlineNode);
$this->assertTrue($scenarios[1]->hasExamples());
/** @var OutlineNode $outline */
$outline = $scenarios[1];
$this->assertTrue($outline->hasExamples());
$this->assertEquals([
['action' => 'act#2', 'outcome' => 'out#2'],
], $scenarios[1]->getExampleTable()->getColumnsHash());
], $outline->getExampleTable()->getColumnsHash());

$this->assertEquals('Scenario#3 HD Remix', $scenarios[2]->getTitle());
}
Expand All @@ -175,10 +181,12 @@ public function testFeatureFilterNodes3()
$this->assertEquals('Scenario#3', $scenarios[1]->getTitle());

$this->assertTrue($scenarios[1] instanceof OutlineNode);
$this->assertTrue($scenarios[1]->hasExamples());
/** @var OutlineNode $outline */
$outline = $scenarios[1];
$this->assertTrue($outline->hasExamples());
$this->assertEquals([
['action' => 'act#2', 'outcome' => 'out#2'],
], $scenarios[1]->getExampleTable()->getColumnsHash());
], $outline->getExampleTable()->getColumnsHash());

/*****************
* Node 2 *
Expand All @@ -192,10 +200,12 @@ public function testFeatureFilterNodes3()
$this->assertEquals('Scenario#3', $scenarios[1]->getTitle());

$this->assertTrue($scenarios[1] instanceof OutlineNode);
$this->assertTrue($scenarios[1]->hasExamples());
/** @var OutlineNode $outline */
$outline = $scenarios[1];
$this->assertTrue($outline->hasExamples());
$this->assertEquals([
['action' => 'act#3', 'outcome' => 'out#3'],
], $scenarios[1]->getExampleTable()->getColumnsHash());
], $outline->getExampleTable()->getColumnsHash());

/*****************
* Node 3 *
Expand All @@ -208,10 +218,12 @@ public function testFeatureFilterNodes3()
$this->assertEquals('Scenario#3', $scenarios[0]->getTitle());

$this->assertTrue($scenarios[0] instanceof OutlineNode);
$this->assertTrue($scenarios[0]->hasExamples());
/** @var OutlineNode $outline */
$outline = $scenarios[0];
$this->assertTrue($outline->hasExamples());
$this->assertEquals([
['action' => 'act#1', 'outcome' => 'out#1'],
], $scenarios[0]->getExampleTable()->getColumnsHash());
], $outline->getExampleTable()->getColumnsHash());

$this->assertEquals('Scenario#3 HD Remix', $scenarios[1]->getTitle());
}
Expand All @@ -233,10 +245,12 @@ public function testFeatureFilterNodes4()
$this->assertEquals('Scenario#3', $scenarios[1]->getTitle());

$this->assertTrue($scenarios[1] instanceof OutlineNode);
$this->assertTrue($scenarios[1]->hasExamples());
/** @var OutlineNode $outline */
$outline = $scenarios[1];
$this->assertTrue($outline->hasExamples());
$this->assertEquals([
['action' => 'act#3', 'outcome' => 'out#3'],
], $scenarios[1]->getExampleTable()->getColumnsHash());
], $outline->getExampleTable()->getColumnsHash());

/*****************
* Node 2 *
Expand All @@ -260,10 +274,12 @@ public function testFeatureFilterNodes4()
$this->assertEquals('Scenario#3', $scenarios[0]->getTitle());

$this->assertTrue($scenarios[0] instanceof OutlineNode);
$this->assertTrue($scenarios[0]->hasExamples());
/** @var OutlineNode $outline */
$outline = $scenarios[0];
$this->assertTrue($outline->hasExamples());
$this->assertEquals([
['action' => 'act#1', 'outcome' => 'out#1'],
], $scenarios[0]->getExampleTable()->getColumnsHash());
], $outline->getExampleTable()->getColumnsHash());

/*****************
* Node 4 *
Expand All @@ -276,9 +292,11 @@ public function testFeatureFilterNodes4()
$this->assertEquals('Scenario#3', $scenarios[0]->getTitle());

$this->assertTrue($scenarios[0] instanceof OutlineNode);
$this->assertTrue($scenarios[0]->hasExamples());
/** @var OutlineNode $outline */
$outline = $scenarios[0];
$this->assertTrue($outline->hasExamples());
$this->assertEquals([
['action' => 'act#2', 'outcome' => 'out#2'],
], $scenarios[0]->getExampleTable()->getColumnsHash());
], $outline->getExampleTable()->getColumnsHash());
}
}
17 changes: 9 additions & 8 deletions tests/Medology/Behat/StoreContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use PHPUnit_Framework_Error;
use PHPUnit_Framework_TestCase;
use stdClass;
use TypeError;

class StoreContextTest extends PHPUnit_Framework_TestCase
{
Expand Down Expand Up @@ -67,6 +66,7 @@ public function testInjectStoredValues()

// test invalid argument for $string
try {
/* @noinspection PhpParamsInspection intentional wrong argument type */
$this->storeContext->injectStoredValues([]);
$this->setExpectedException('PHPUnit_Framework_Error_Warning');
} catch (Exception $e) {
Expand Down Expand Up @@ -174,7 +174,8 @@ public function testInjectStoredValues()
}

// test function with no return
$badFn = function ($a) {
$badFn = function (/* @noinspection PhpUnusedParameterInspection */ $a) {
/** @noinspection PhpUnusedLocalVariableInspection */
$a = 1;
};

Expand All @@ -187,7 +188,7 @@ public function testInjectStoredValues()
}

// test function with bad return
$badFn = function ($a) {
$badFn = function (/* @noinspection PhpUnusedParameterInspection */ $a) {
return 'bad return';
};

Expand All @@ -199,7 +200,7 @@ public function testInjectStoredValues()
$this->assertEquals('The $onGetFn method must return an object or an array!', $e->getMessage());
}

$badFn = function ($a) {
$badFn = function (/* @noinspection PhpUnusedParameterInspection */ $a) {
return function () {
};
};
Expand All @@ -221,7 +222,7 @@ public function testInjectStoredValues()
$this->storeContext->injectStoredValues('(the test_property_1 of the testObj)', $goodFn)
);

// test accessing property after unsetting with callback
// test accessing property after un-setting with callback
$goodFn = function ($thing) {
unset($thing->test_property_1);

Expand Down Expand Up @@ -298,10 +299,10 @@ function ($a, $b, $c) {
$wrongReturnTypes = [
function ($a, $b) {
},
function ($a, $b) {
function (/* @noinspection PhpUnusedParameterInspection */ $a, $b) {
return '';
},
function ($a, $b) {
function (/* @noinspection PhpUnusedParameterInspection */ $a, $b) {
return function () {
};
},
Expand All @@ -321,7 +322,7 @@ function ($a, $b) {
$this->storeContext->injectStoredValues(
'(the test_property_1 of the testObj)',
null,
function ($a, $b) {
function (/* @noinspection PhpUnusedParameterInspection */ $a, $b) {
return false;
}
);
Expand Down
2 changes: 1 addition & 1 deletion web/button-disabled.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
document.getElementById("disabled-button").removeAttribute("disabled");
}
function disableEnabledButton() {
document.getElementById("enabled-button").setAttribute("disabled", null);
document.getElementById("enabled-button").setAttribute("disabled", '');
}
</script>
</head>
Expand Down
2 changes: 1 addition & 1 deletion web/image-load-test.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<h1>Valid Image Link</h1>
<img src="img/medology.png" id="valid-image" alt="Valid Image" />
<h1>Invalid (Broken) Image</h1>
<img src="img/doesnotexist.png" id="invalid-image" alt="Invalid Image" />
<img src="img/doesNotExist.png" id="invalid-image" alt="Invalid Image" />
</body>

</html>
Loading

0 comments on commit 6b3776f

Please sign in to comment.