Skip to content

Commit a9bc272

Browse files
committed
Address mutation testing issues
1 parent 3e5c466 commit a9bc272

File tree

8 files changed

+42
-13
lines changed

8 files changed

+42
-13
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
build/
22
vendor/
33
composer.lock
4+
infection.json.dist
5+
infection-log.txt
46
psalm.xml

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ before_install:
1515

1616
install:
1717
- mkdir -p build/php_codesniffer build/php-cs-fixer build/ocular
18-
- composer require --no-suggest --no-progress -n -a -d build/php-cs-fixer "friendsofphp/php-cs-fixer:^2.12"
18+
- composer require --no-suggest --no-progress -n -a -d build/php-cs-fixer "friendsofphp/php-cs-fixer:^2.13"
1919
- composer require --no-suggest --no-progress -n -a -d build/php_codesniffer "squizlabs/php_codesniffer:^3.3"
2020
- composer require --no-suggest --no-progress -n -a -d build/ocular "scrutinizer/ocular:^1.5"
2121
- composer update --no-suggest --no-progress -n -a

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Changed
9+
- Improved tests and some failure conditions with mutation testing
810

911
## [0.2.1] - 2018-07-18
1012
### Added

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
"psr/container-implementation": "^1.0"
2626
},
2727
"require-dev": {
28-
"phpunit/phpunit": "^7.2",
29-
"riimu/php-cs-fixer-config": "^0.1.0",
28+
"phpunit/phpunit": "^7.3",
29+
"riimu/php-cs-fixer-config": "^0.1.1",
3030
"riimu/sami-config": "^0.1.0"
3131
},
3232
"autoload": {

src/AbstractEntryProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function getMethods(): array
3232
foreach ($reflection->getMethods() as $method) {
3333
$identifier = $this->getMethodIdentifier($method);
3434

35-
if ($identifier !== null) {
35+
if (!\is_null($identifier)) {
3636
$methods[$identifier] = $method->getName();
3737
}
3838
}
@@ -51,13 +51,13 @@ private function getMethodIdentifier(\ReflectionMethod $method): ?string
5151
return null;
5252
}
5353

54-
if (strncmp($method->getName(), '__', 2) === 0) {
54+
if (preg_match('/^__[^_]/', $method->getName())) {
5555
return null;
5656
}
5757

5858
$type = $method->getReturnType();
5959

60-
if ($type === null || $type->isBuiltin()) {
60+
if (!$type instanceof \ReflectionType || $type->isBuiltin()) {
6161
return null;
6262
}
6363

src/Container.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ private function isConstantValue($value): bool
116116
return true;
117117
}
118118

119-
return $value === null || is_scalar($value);
119+
return is_scalar($value) || \is_null($value);
120120
}
121121

122122
/**

src/ContainerBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private function getWiredParameters(\ReflectionClass $reflection, array $overrid
9292
{
9393
$constructor = $reflection->getConstructor();
9494

95-
if ($constructor === null) {
95+
if (!$constructor instanceof \ReflectionMethod) {
9696
return [];
9797
}
9898

@@ -108,7 +108,7 @@ private function getWiredParameters(\ReflectionClass $reflection, array $overrid
108108

109109
$type = $parameter->getType();
110110

111-
if ($type === null || $type->isBuiltin()) {
111+
if (!$type instanceof \ReflectionType || $type->isBuiltin()) {
112112
throw new \InvalidArgumentException(
113113
sprintf("Missing autowired parameter '%s' for '%s'", $name, $reflection->getName())
114114
);

tests/tests/ContainerTest.php

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,20 @@ public static function getDate(): \DateTime
5656
public function testProviderEntry()
5757
{
5858
$testClass = new class() extends AbstractEntryProvider {
59-
public function getFoo()
59+
public function getNow()
6060
{
61-
return 'foo';
61+
return new \DateTime();
6262
}
6363
};
6464

6565
$this->withContainer([
6666
\get_class($testClass) => new CallableEntry([\get_class($testClass), 'initialize']),
67-
'foo_value' => new ProviderEntry([$testClass, 'getFoo']),
67+
'now' => new ProviderEntry([$testClass, 'getNow']),
6868
], function (Container $container) {
69-
$this->assertSame('foo', $container->get('foo_value'));
69+
$now = $container->get('now');
70+
71+
$this->assertInstanceOf(\DateTime::class, $now);
72+
$this->assertSame($now, $container->get('now'));
7073
});
7174
}
7275

@@ -82,6 +85,11 @@ public function testWiredEntry()
8285

8386
$this->assertInstanceOf(\DateTime::class, $date);
8487
$this->assertSame(strtotime($time), $date->getTimestamp());
88+
89+
$other = $container->get(\DateTime::class);
90+
91+
$this->assertInstanceOf(\DateTime::class, $other);
92+
$this->assertSame($date, $other);
8593
});
8694
}
8795

@@ -178,6 +186,23 @@ public function testDoubleCaching()
178186
});
179187
}
180188

189+
public function testSortingOnCache()
190+
{
191+
$container = $this->getCachedContainer([
192+
'b' => 'b_value',
193+
'c' => 'c_value',
194+
'a' => 'a_value',
195+
]);
196+
197+
$types = new \ReflectionProperty($container, 'types');
198+
$types->setAccessible(true);
199+
$parameters = new \ReflectionProperty($container, 'parameters');
200+
$parameters->setAccessible(true);
201+
202+
$this->assertSame(['a', 'b', 'c'], array_keys($types->getValue($container)));
203+
$this->assertSame(['a', 'b', 'c'], array_keys($parameters->getValue($container)));
204+
}
205+
181206
private function withContainer(array $values, \Closure $suite)
182207
{
183208
$suite($this->getContainer($values));

0 commit comments

Comments
 (0)