Skip to content

Commit 5be3314

Browse files
committed
chore: Pull in latest upstream changes
2 parents c85d1ad + 518f02b commit 5be3314

File tree

7 files changed

+315
-13
lines changed

7 files changed

+315
-13
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ test export-ignore
22
.gitignore export-ignore
33
.gitattributes export-ignore
44
phpunit.xml* export-ignore
5+
phpcs.xml export-ignore

.gitignore

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
# Text-Editor backup files
2-
*~
3-
41
# ignore dependencies
52
vendor
63

74
# ignore test/coverage reports
85
test/coverage
6+
coverage.clover.xml
97

108
# ignore phpunit cache
119
.phpunit.result.cache
12-
13-
# Ignore IDEs
14-
.idea
15-
.atom

composer.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,21 @@
2828
}
2929
},
3030
"scripts": {
31-
"test": "vendor/bin/phpunit"
31+
"test": "vendor/bin/phpunit",
32+
"test-coverage-clover": "vendor/bin/phpunit --coverage-clover=coverage.clover.xml",
33+
"test-coverage-html": "vendor/bin/phpunit --coverage-html=test/coverage",
34+
"lint": "vendor/bin/phpcs --standard=phpcs.xml src/*"
35+
},
36+
"scripts-descriptions": {
37+
"test": "Runs the phpunit testsuite",
38+
"test-coverage-clover": "Runs the phpunit testsuite and generates coverage in the clover format in the file 'coverage.clover.xml'",
39+
"test-coverage-html": "Runs the phpunit testsuite and generates coverage in html format in the directory 'test/coverage'.",
40+
"lint": "Runs PHP_CodeSniffer on 'src/*'"
3241
},
3342
"require-dev": {
3443
"php-mock/php-mock-prophecy": "^0.0.2",
35-
"psr/container": "^1.0"
44+
"psr/container": "^1.0",
45+
"squizlabs/php_codesniffer": ">=3.4 <3.5.0",
46+
"slevomat/coding-standard": "^5.0"
3647
}
3748
}

composer.lock

Lines changed: 139 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpcs.xml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ruleset name="cross-phpunit-utils-standard">
3+
<config name="installed_paths" value="../../slevomat/coding-standard"/>
4+
<exclude-pattern>**/test/*</exclude-pattern>
5+
<exclude-pattern>**/vendor/*</exclude-pattern>
6+
7+
8+
<rule ref="PSR2">
9+
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.Indent" />
10+
</rule>
11+
<rule ref="PSR12"/>
12+
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
13+
<properties>
14+
<property name="newlinesCountBetweenOpenTagAndDeclare" value="2" />
15+
<property name="newlinesCountAfterDeclare" value="2" />
16+
<property name="spacesCountAroundEqualsSign" value="0" />
17+
</properties>
18+
</rule>
19+
<rule ref="SlevomatCodingStandard.Arrays.DisallowImplicitArrayCreation" />
20+
<rule ref="SlevomatCodingStandard.Classes.UnusedPrivateElements">
21+
<properties>
22+
<property name="alwaysUsedPropertiesAnnotations" type="array">
23+
<element value="@ODM\" />
24+
</property>
25+
</properties>
26+
</rule>
27+
<rule ref="SlevomatCodingStandard.Functions.UnusedInheritedVariablePassedToClosure" />
28+
<rule ref="SlevomatCodingStandard.Functions.UselessParameterDefaultValue" />
29+
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses">
30+
<properties>
31+
<property name="searchAnnotations" value="true" />
32+
</properties>
33+
</rule>
34+
<rule ref="SlevomatCodingStandard.Namespaces.UseFromSameNamespace" />
35+
<rule ref="SlevomatCodingStandard.Namespaces.UselessAlias" />
36+
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses">
37+
<properties>
38+
<property name="caseSensitive" value="true" />
39+
</properties>
40+
</rule>
41+
<rule ref="SlevomatCodingStandard.Namespaces.NamespaceDeclaration" />
42+
<rule ref="SlevomatCodingStandard.Variables.UnusedVariable" />
43+
<rule ref="SlevomatCodingStandard.Variables.UselessVariable" />
44+
<rule ref="SlevomatCodingStandard.TypeHints.LongTypeHints" />
45+
<rule ref="SlevomatCodingStandard.PHP.TypeCast" />
46+
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing">
47+
<properties>
48+
<property name="spacesCountBeforeColon" value="0" />
49+
</properties>
50+
</rule>
51+
<rule ref="SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue" />
52+
</ruleset>

src/TestCase/TestSetterAndGetterTrait.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public function testSetterAndGetter($name, $spec = null): void
157157
[$setter, $setterArgs] = $spec['setter'];
158158
$setterValue = $target->$setter($value, ...$setterArgs);
159159

160-
if ('__SETTER_AND_GETTER__' != $spec['setter_value']) {
160+
if ($spec['setter_value'] !== '__SETTER_AND_GETTER__') {
161161
$spec['setter_assert']($spec['setter_value'], $setterValue);
162162
}
163163
}
@@ -166,7 +166,7 @@ public function testSetterAndGetter($name, $spec = null): void
166166
[$getter, $getterArgs] = $spec['getter'];
167167
$getterValue = $target->$getter(...$getterArgs);
168168

169-
if ($spec['expect'] != '__SETTER_AND_GETTER__') {
169+
if ($spec['expect'] !== '__SETTER_AND_GETTER__') {
170170
$value = $spec['expect'];
171171
}
172172

@@ -255,7 +255,7 @@ private function setterAndGetterNormalizeSpec($spec, string $name, object $targe
255255
break;
256256

257257
case 'setter_value':
258-
if ('__SELF__' == $value) {
258+
if ('__SELF__' === $value) {
259259
$value = $target;
260260
if (!isset($spec['setter_assert'])) {
261261
$normalized['setter_assert'] = [static::class, 'assertSame'];
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?php
2+
3+
/**
4+
* phpunit-utils
5+
*
6+
* @filesource
7+
* @copyright 2020 CROSS Solution <https://www.cross-solution.de>
8+
* @license MIT
9+
*/
10+
11+
declare(strict_types=1);
12+
namespace Cross\TestUtilsTest\TestCase\TestSetterAndGetterTrait;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Cross\TestUtils\TestCase\TestSetterAndGetterTrait;
16+
17+
/**
18+
* Testcase for \Cross\TestUtils\TestCase\TestSetterAndGetterTrait
19+
*
20+
* @covers \Cross\TestUtils\TestCase\TestSetterAndGetterTrait
21+
* @author Mathias Gelhausen <gelhausen@cross-solution.de>
22+
* @group Cross.TestUtils
23+
* @group Cross.TestUtils.TestCase
24+
* @group Cross.TestUtils.TestCase.TestSetterAndGetterTrait
25+
*/
26+
class SpecifyExpectedValueTest extends TestCase
27+
{
28+
public function setUp(): void
29+
{
30+
$dummy = new class
31+
{
32+
public $attr;
33+
public $expect = 'expected';
34+
35+
public function setAttr($v)
36+
{
37+
$this->attr = $v;
38+
return $this->expect;
39+
}
40+
41+
public function getAttr()
42+
{
43+
return $this->expect;
44+
}
45+
};
46+
47+
$this->target = new class($dummy)
48+
{
49+
use TestSetterAndGetterTrait;
50+
51+
public $target;
52+
public $testSetterAndGetter;
53+
public static $result;
54+
55+
public function __construct($dummy)
56+
{
57+
$this->target = $dummy;
58+
static::$result = null;
59+
}
60+
61+
public static function assertEquals($expect)
62+
{
63+
static::$result = $expect;
64+
}
65+
66+
public static function assertSame($expect)
67+
{
68+
static::$result = $expect;
69+
}
70+
};
71+
}
72+
73+
/**
74+
* @testWith [true, "a string"]
75+
* [true, [1,2,3]]
76+
* [true, "stdClass", "object"]
77+
*
78+
*/
79+
public function testSpecifyingExpectedGetterValues($expect, $value, $type = null)
80+
{
81+
$this->target->target->expect = $expect;
82+
$this->target->testSetterAndGetter(
83+
'attr',
84+
['value' . ($type ? "_$type" : '') => $value, 'expect' => $expect]
85+
);
86+
87+
static::assertEquals($expect, $this->target::$result);
88+
}
89+
90+
/**
91+
* @testWith [true]
92+
*/
93+
public function testSpecifiyingExpectedSetterValues($expect, $type = null)
94+
{
95+
if ($type === 'object') {
96+
$expect = new $expect();
97+
}
98+
$this->target->target->expect = $expect;
99+
$this->target->testSetterAndGetter(
100+
'attr',
101+
['getter' => false, 'value' => 'irrelevant', 'setter_value' => $expect]
102+
);
103+
104+
static::assertEquals($expect, $this->target::$result);
105+
}
106+
}

0 commit comments

Comments
 (0)