Skip to content

Commit 8685a19

Browse files
authored
Merge pull request #13 from jakzal/php-scoper
Scope dependencies
2 parents cd965fc + a7a252c commit 8685a19

File tree

10 files changed

+104
-3
lines changed

10 files changed

+104
-3
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@
1414
/phpunit.xml.dist export-ignore
1515
/tests export-ignore
1616
/tools export-ignore
17+
/scoper.inc.php export-ignore

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ install:
1212
- if [[ $deps = low ]]; then make update-min; else make install; fi
1313
script:
1414
- if [[ $deps = low ]]; then make test-min; else make test; fi
15-
- make package
15+
- make package test-package
1616
deploy:
1717
provider: releases
1818
api_key:

Makefile

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ test: vendor cs deptrac phpunit infection
2525
test-min: update-min cs deptrac phpunit infection
2626
.PHONY: test-min
2727

28+
test-package: package test-package-tools
29+
cd tests/phar && ./tools/phpunit
30+
.PHONY: test-package
31+
2832
cs: tools/php-cs-fixer
2933
tools/php-cs-fixer --dry-run --allow-risky=yes --no-interaction --ansi fix
3034
.PHONY: cs
@@ -48,15 +52,21 @@ phpunit: tools/phpunit
4852
tools: tools/php-cs-fixer tools/deptrac tools/infection tools/box
4953
.PHONY: tools
5054

55+
test-package-tools: tests/phar/tools/phpunit tests/phar/tools/phpunit.d/zalas-phpunit-injector-extension.phar
56+
.PHONY: test-package-tools
57+
5158
clean:
5259
rm -rf build
60+
rm -rf vendor
61+
find tools -not -path '*/\.*' -type f -delete
62+
find tests/phar/tools -not -path '*/\.*' -type f -delete
5363
.PHONY: clean
5464

5565
package: tools/box
5666
$(eval VERSION=$(shell git describe --abbrev=0 --tags 2> /dev/null | sed -e 's/^v//' || echo 'dev'))
5767
@rm -rf build/phar && mkdir -p build/phar
5868

59-
cp -r src LICENSE composer.json build/phar
69+
cp -r src LICENSE composer.json scoper.inc.php build/phar
6070
sed -e 's/@@version@@/$(VERSION)/g' manifest.xml.in > build/phar/manifest.xml
6171

6272
cd build/phar && \
@@ -89,4 +99,12 @@ tools/infection.pubkey:
8999
curl -Ls https://github.com/infection/infection/releases/download/0.9.0/infection.phar.pubkey -o tools/infection.pubkey
90100

91101
tools/box:
92-
curl -Ls https://github.com/humbug/box/releases/download/3.0.0-beta.0/box.phar -o tools/box && chmod +x tools/box
102+
curl -Ls https://github.com/humbug/box/releases/download/3.0.0-beta.4/box.phar -o tools/box && chmod +x tools/box
103+
104+
tests/phar/tools/phpunit:
105+
curl -Ls https://phar.phpunit.de/phpunit-7.phar -o tests/phar/tools/phpunit && chmod +x tests/phar/tools/phpunit
106+
107+
tests/phar/tools/phpunit.d/zalas-phpunit-injector-extension.phar: build/zalas-phpunit-injector-extension.phar
108+
cp build/zalas-phpunit-injector-extension.phar tests/phar/tools/phpunit.d/zalas-phpunit-injector-extension.phar
109+
110+
build/zalas-phpunit-injector-extension.phar: package

box.json.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
"exclude-composer-files": true,
88
"check-requirements": false,
99
"main": "vendor/autoload.php",
10+
"compactors": [
11+
"KevinGH\\Box\\Compactor\\PhpScoper"
12+
],
1013
"banner": [
1114
"This file is part of the zalas/phpunit-injector project.",
1215
"",

phpunit.xml.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<testsuites>
1111
<testsuite name="default">
1212
<directory suffix="Test.php">tests</directory>
13+
<exclude>tests/phar</exclude>
1314
</testsuite>
1415
</testsuites>
1516

scoper.inc.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php declare(strict_types=1);
2+
3+
return [
4+
'whitelist' => [
5+
'Psr\Container\*',
6+
'PHPUnit\Framework\*',
7+
'Symfony\Component\*',
8+
'Zalas\Injector\*',
9+
],
10+
];

tests/phar/phpunit.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.2/phpunit.xsd"
4+
beStrictAboutOutputDuringTests="true"
5+
beStrictAboutTodoAnnotatedTests="true"
6+
verbose="true"
7+
extensionsDirectory="tools/phpunit.d">
8+
<testsuites>
9+
<testsuite name="default">
10+
<directory suffix="Test.php">tests</directory>
11+
</testsuite>
12+
</testsuites>
13+
14+
<listeners>
15+
<listener class="Zalas\Injector\PHPUnit\TestListener\ServiceInjectorListener" />
16+
</listeners>
17+
18+
<filter>
19+
<whitelist processUncoveredFilesFromWhitelist="true">
20+
<directory suffix=".php">src</directory>
21+
</whitelist>
22+
</filter>
23+
</phpunit>

tests/phar/tests/PharTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
use PHPUnit\Framework\TestCase;
5+
use Psr\Container\ContainerInterface;
6+
use Psr\Container\NotFoundExceptionInterface;
7+
use Zalas\Injector\PHPUnit\TestCase\ServiceContainerTestCase;
8+
9+
class PharTest extends TestCase implements ServiceContainerTestCase
10+
{
11+
/**
12+
* @var stdClass
13+
* @inject foo.service
14+
*/
15+
private $service;
16+
17+
public function test_it_injects_services_into_test_cases()
18+
{
19+
$this->assertInstanceOf(stdClass::class, $this->service);
20+
}
21+
22+
public function createContainer(): ContainerInterface
23+
{
24+
return new class implements ContainerInterface {
25+
public function get($id)
26+
{
27+
if ('foo.service' === $id) {
28+
return new stdClass();
29+
}
30+
31+
throw new class extends \Exception implements NotFoundExceptionInterface {
32+
};
33+
}
34+
35+
public function has($id)
36+
{
37+
return \in_array($id, ['foo.service'], true);
38+
}
39+
};
40+
}
41+
}

tests/phar/tools/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

tests/phar/tools/phpunit.d/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

0 commit comments

Comments
 (0)