Skip to content

Commit e22c1d6

Browse files
committed
Reorganised tests
1 parent d65e2aa commit e22c1d6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+116
-730
lines changed

.github/workflows/tests.yml

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -89,73 +89,3 @@ jobs:
8989
uses: sudo-bot/action-scrutinizer@latest
9090
with:
9191
cli-args: "--format=php-clover coverage.clover"
92-
93-
guzzle:
94-
strategy:
95-
fail-fast: true
96-
matrix:
97-
guzzle: ["5", "6"]
98-
99-
name: "Integration test for Guzzle ${{ matrix.guzzle }}"
100-
101-
runs-on: "ubuntu-latest"
102-
103-
steps:
104-
- name: "Checkout code"
105-
uses: "actions/checkout@v2"
106-
107-
- name: "Setup PHP"
108-
uses: "shivammathur/setup-php@v2"
109-
with:
110-
php-version: "8.0"
111-
extensions: "curl, soap"
112-
tools: "composer:v2"
113-
coverage: "pcov"
114-
115-
- name: "Check Composer configuration"
116-
run: "composer validate --strict"
117-
118-
- name: "Install dependencies"
119-
run: "composer update --prefer-dist --no-interaction --no-progress"
120-
121-
- name: "Execute tests"
122-
run: "cd tests/integration/guzzle/${{ matrix.guzzle }}/ && composer update --prefer-dist --no-interaction --no-progress && ../../../../vendor/bin/phpunit --coverage-clover=coverage.clover"
123-
124-
- name: Upload Scrutinizer coverage
125-
uses: sudo-bot/action-scrutinizer@latest
126-
with:
127-
cli-args: "--format=php-clover coverage.clover"
128-
129-
soap:
130-
strategy:
131-
fail-fast: true
132-
133-
name: "SOAP integration test"
134-
135-
runs-on: "ubuntu-latest"
136-
137-
steps:
138-
- name: "Checkout code"
139-
uses: "actions/checkout@v2"
140-
141-
- name: "Setup PHP"
142-
uses: "shivammathur/setup-php@v2"
143-
with:
144-
php-version: "8.0"
145-
extensions: "curl, soap"
146-
tools: "composer:v2"
147-
coverage: "pcov"
148-
149-
- name: "Check Composer configuration"
150-
run: "composer validate --strict"
151-
152-
- name: "Install dependencies"
153-
run: "composer update --prefer-dist --no-interaction --no-progress"
154-
155-
- name: "Execute tests"
156-
run: "cd tests/integration/soap/ && composer update --prefer-dist --no-interaction --no-progress && ../../../vendor/bin/phpunit --coverage-clover=coverage.clover"
157-
158-
- name: Upload Scrutinizer coverage
159-
uses: sudo-bot/action-scrutinizer@latest
160-
with:
161-
cli-args: "--format=php-clover coverage.clover"

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"symfony/event-dispatcher": "^5.0"
2323
},
2424
"require-dev": {
25+
"guzzlehttp/guzzle": "^7.0",
2526
"phpunit/phpunit": "^9.5.0",
2627
"mikey179/vfsstream": "^1.6.10",
2728
"phpstan/phpstan": "^0.12.92",
@@ -37,8 +38,8 @@
3738
}
3839
},
3940
"autoload-dev": {
40-
"classmap": [
41-
"tests/"
42-
]
41+
"psr-4": {
42+
"VCR\\Tests\\": "tests"
43+
}
4344
}
4445
}

phpstan.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ parameters:
55
level: max
66
paths:
77
- src
8-
- tests/VCR
8+
- tests

phpunit.xml.dist

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,16 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
3-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.8/phpunit.xsd"
5-
backupGlobals="false"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
9-
colors="true"
10-
bootstrap="tests/bootstrap.php"
11-
>
12-
13-
<testsuites>
14-
<testsuite name="VCR Test Suit">
15-
<directory>./tests/VCR</directory>
16-
</testsuite>
17-
</testsuites>
18-
19-
<filter>
20-
<whitelist processUncoveredFilesFromWhitelist="true">
21-
<directory suffix=".php">src</directory>
22-
</whitelist>
23-
</filter>
24-
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" colors="true" bootstrap="tests/bootstrap.php">
3+
<coverage processUncoveredFiles="true">
4+
<include>
5+
<directory suffix=".php">src</directory>
6+
</include>
7+
</coverage>
8+
<testsuites>
9+
<testsuite name="Unit">
10+
<directory>./tests/Unit</directory>
11+
</testsuite>
12+
<testsuite name="Integration">
13+
<directory>./tests/Integration</directory>
14+
</testsuite>
15+
</testsuites>
2516
</phpunit>

tests/integration/guzzle/6/test/AsyncTest.php renamed to tests/Integration/Guzzle/AsyncTest.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@
22

33
declare(strict_types=1);
44

5-
namespace VCR\Example;
5+
namespace VCR\Tests\Integration\Guzzle;
66

77
use GuzzleHttp\Client;
88
use org\bovigo\vfs\vfsStream;
99
use PHPUnit\Framework\TestCase;
1010

11-
/**
12-
* Tests example request.
13-
*/
14-
class AsyncTest extends TestCase
11+
final class AsyncTest extends TestCase
1512
{
1613
public const TEST_GET_URL = 'https://httpbin.org/get';
1714
public const TEST_GET_URL_2 = 'https://httpbin.org/get?foo=42';
@@ -35,12 +32,12 @@ public function testAsyncLock(): void
3532
// Let's check that we can perform 2 async request on different URLs without locking.
3633
// Solves https://github.com/php-vcr/php-vcr/issues/211
3734

38-
$this->assertValidGETResponse(\GuzzleHttp\json_decode($response->getBody(), true));
35+
$this->assertValidGETResponse(\GuzzleHttp\json_decode($response->getBody()->getContents(), true));
3936

4037
\VCR\VCR::turnOff();
4138
}
4239

43-
protected function assertValidGETResponse($info): void
40+
protected function assertValidGETResponse(mixed $info): void
4441
{
4542
$this->assertIsArray($info, 'Response is not an array.');
4643
$this->assertArrayHasKey('url', $info, 'API did not return any value.');

tests/integration/guzzle/6/test/ErrorTest.php renamed to tests/Integration/Guzzle/ErrorTest.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@
22

33
declare(strict_types=1);
44

5-
namespace VCR\Example;
5+
namespace VCR\Tests\Integration\Guzzle;
66

77
use GuzzleHttp\Client;
88
use GuzzleHttp\Exception\ConnectException;
99
use org\bovigo\vfs\vfsStream;
1010
use PHPUnit\Framework\TestCase;
1111

12-
/**
13-
* Tests behaviour when an error occurs.
14-
*/
15-
class ErrorTest extends TestCase
12+
final class ErrorTest extends TestCase
1613
{
1714
public const TEST_GET_URL = 'http://localhost:9959';
1815

@@ -45,8 +42,4 @@ public function testConnectException(): void
4542
$this->assertTrue($catched);
4643
\VCR\VCR::turnOff();
4744
}
48-
49-
protected function assertValidGETResponse($info): void
50-
{
51-
}
5245
}

tests/integration/soap/src/VCR/Example/ExampleSoapClient.php renamed to tests/Integration/Soap/ExampleSoapClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace VCR\Example;
5+
namespace VCR\Tests\Integration\Soap;
66

77
/**
88
* Converts temperature units from webservicex.
@@ -13,7 +13,7 @@ class ExampleSoapClient
1313
{
1414
public const EXAMPLE_WSDL = 'http://www.dataaccess.com/webservicesserver/numberconversion.wso?WSDL';
1515

16-
public function call($number = 12)
16+
public function call(int $number = 12): string
1717
{
1818
$client = new \SoapClient(self::EXAMPLE_WSDL, ['soap_version' => \SOAP_1_2]);
1919
$response = $client->NumberToWords(['ubiNum' => $number]);

tests/integration/soap/test/VCR/Example/ExampleSoapClientTest.php renamed to tests/Integration/Soap/ExampleSoapClientTest.php

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22

33
declare(strict_types=1);
44

5-
namespace VCR\Example;
5+
namespace VCR\Tests\Integration\Soap;
66

77
use org\bovigo\vfs\vfsStream;
88
use PHPUnit\Framework\TestCase;
9-
use SoapFault;
109

1110
/**
1211
* Converts temperature units from webservicex.
1312
*
1413
* @see http://www.webservicex.net/New/Home/ServiceDetail/31
1514
*/
16-
class ExampleSoapClientTest extends TestCase
15+
final class ExampleSoapClientTest extends TestCase
1716
{
1817
protected function setUp(): void
1918
{
@@ -45,42 +44,14 @@ public function testCallDirectlyEqualsIntercepted(): void
4544
$this->assertEquals($this->callSoap(), $this->callSoapIntercepted());
4645
}
4746

48-
/**
49-
* This test performs a SOAP request on a buggy WSDL.
50-
* It checks that the non instrumented code and the instrumented code return the same exception.
51-
*/
52-
public function testCallSoapWithError(): void
53-
{
54-
$nonInstrumentedException = null;
55-
try {
56-
$soapClient = new ExampleSoapClient();
57-
$soapClient->callBadUrl();
58-
} catch (SoapFault $e) {
59-
$nonInstrumentedException = $e;
60-
}
61-
$this->assertNotNull($nonInstrumentedException);
62-
$catched = false;
63-
\VCR\VCR::turnOn();
64-
\VCR\VCR::insertCassette('test-cassette.yml');
65-
try {
66-
$soapClient = new ExampleSoapClient();
67-
$soapClient->callBadUrl();
68-
} catch (SoapFault $e) {
69-
$catched = true;
70-
$this->assertEquals($e->getMessage(), $nonInstrumentedException->getMessage());
71-
}
72-
$this->assertTrue($catched);
73-
\VCR\VCR::turnOff();
74-
}
75-
76-
protected function callSoap()
47+
protected function callSoap(): mixed
7748
{
7849
$soapClient = new ExampleSoapClient();
7950

80-
return $soapClient->call(12);
51+
return $soapClient->call();
8152
}
8253

83-
protected function callSoapIntercepted()
54+
protected function callSoapIntercepted(): mixed
8455
{
8556
\VCR\VCR::turnOn();
8657
\VCR\VCR::insertCassette('test-cassette.yml');

tests/VCR/CassetteTest.php renamed to tests/Unit/CassetteTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22

33
declare(strict_types=1);
44

5-
namespace VCR;
5+
namespace VCR\Tests\Unit;
66

77
use org\bovigo\vfs\vfsStream;
88
use PHPUnit\Framework\TestCase;
9+
use VCR\Cassette;
10+
use VCR\Configuration;
11+
use VCR\Request;
12+
use VCR\Response;
13+
use VCR\Storage\Yaml;
914

1015
final class CassetteTest extends TestCase
1116
{
@@ -14,7 +19,7 @@ final class CassetteTest extends TestCase
1419
protected function setUp(): void
1520
{
1621
vfsStream::setup('test');
17-
$this->cassette = new Cassette('test', new Configuration(), new Storage\Yaml(vfsStream::url('test/'), 'json_test'));
22+
$this->cassette = new Cassette('test', new Configuration(), new Yaml(vfsStream::url('test/'), 'json_test'));
1823
}
1924

2025
public function testGetName(): void

tests/VCR/CodeTransform/AbstractCodeTransformTest.php renamed to tests/Unit/CodeTransform/AbstractCodeTransformTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
declare(strict_types=1);
44

5-
namespace VCR\CodeTransform;
5+
namespace VCR\Tests\Unit\CodeTransform;
66

77
use PHPUnit\Framework\MockObject\MockObject;
88
use PHPUnit\Framework\TestCase;
9+
use VCR\CodeTransform\AbstractCodeTransform;
910

1011
final class AbstractCodeTransformTest extends TestCase
1112
{

0 commit comments

Comments
 (0)