Skip to content

Commit

Permalink
Merge pull request #44 from SimonFrings/tests
Browse files Browse the repository at this point in the history
Run tests on PHPUnit 9 and update PHPUnit configuration schema for PHPUnit 9.3
  • Loading branch information
clue authored Oct 14, 2020
2 parents 140f9a4 + a0c0ceb commit dab2f42
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 52 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
/.travis.yml export-ignore
/examples/ export-ignore
/phpunit.xml.dist export-ignore
/phpunit.xml.legacy export-ignore
/tests/ export-ignore
9 changes: 4 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ language: php
# lock distro so new future defaults will not break the build
dist: trusty

matrix:
jobs:
include:
- php: 5.3
dist: precise
Expand All @@ -19,10 +19,9 @@ matrix:
allow_failures:
- php: hhvm-3.18

sudo: false

install:
- composer install --no-interaction
- composer install

script:
- vendor/bin/phpunit --coverage-text
- if [[ "$TRAVIS_PHP_VERSION" > "7.2" ]]; then vendor/bin/phpunit --coverage-text; fi
- if [[ "$TRAVIS_PHP_VERSION" < "7.3" ]]; then vendor/bin/phpunit --coverage-text -c phpunit.xml.legacy; fi
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
},
"require-dev": {
"clue/block-react": "^1.0",
"phpunit/phpunit": "^7.0 || ^6.4 || ^5.7 || ^4.8.35"
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35"
}
}
19 changes: 12 additions & 7 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap="vendor/autoload.php" colors="true">
<!-- PHPUnit configuration file with new format for PHPUnit 9.3+ -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
cacheResult="false">
<testsuites>
<testsuite>
<testsuite name="Soap Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<coverage>
<include>
<directory>./src/</directory>
</whitelist>
</filter>
</phpunit>
</include>
</coverage>
</phpunit>
18 changes: 18 additions & 0 deletions phpunit.xml.legacy
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- PHPUnit configuration file with old format for PHPUnit 9.2 or older -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/4.8/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true">
<testsuites>
<testsuite name="Soap Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./src/</directory>
</whitelist>
</filter>
</phpunit>
85 changes: 49 additions & 36 deletions tests/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,18 @@ class FunctionalTest extends TestCase

// download WSDL file only once for all test cases
private static $wsdl;
public static function setUpBeforeClass()
/**
* @beforeClass
*/
public static function setUpFileBeforeClass()
{
self::$wsdl = file_get_contents('http://www.thomas-bayer.com/axis2/services/BLZService?wsdl');
}

public function setUp()
/**
* @before
*/
public function setUpClient()
{
$this->loop = \React\EventLoop\Factory::create();
$this->client = new Client(new Browser($this->loop), self::$wsdl);
Expand All @@ -51,7 +57,7 @@ public function testBlzService()

$result = Block\await($promise, $this->loop);

$this->assertInternalType('object', $result);
$this->assertIsTypeObject($result);
$this->assertTrue(isset($result->details));
$this->assertTrue(isset($result->details->bic));
}
Expand Down Expand Up @@ -93,7 +99,7 @@ public function testBlzServiceWithSoapV12()

$result = Block\await($promise, $this->loop);

$this->assertInternalType('object', $result);
$this->assertIsTypeObject($result);
$this->assertTrue(isset($result->details));
$this->assertTrue(isset($result->details->bic));
}
Expand All @@ -113,72 +119,56 @@ public function testBlzServiceNonWsdlModeReturnedWithoutOuterResultStructure()

$result = Block\await($promise, $this->loop);

$this->assertInternalType('object', $result);
$this->assertIsTypeObject($result);
$this->assertFalse(isset($result->details));
$this->assertTrue(isset($result->bic));
}

/**
* @expectedException RuntimeException
* @expectedExeptionMessage redirects
*/
public function testBlzServiceWithRedirectLocationRejectsWithRuntimeException()
{
$this->client = new Client(new Browser($this->loop), null, array(
'location' => 'http://httpbin.org/redirect-to?url=' . rawurlencode('http://www.thomas-bayer.com/axis2/services/BLZService'),
'location' => 'http://httpbingo.org/redirect-to?url=' . rawurlencode('http://www.thomas-bayer.com/axis2/services/BLZService'),
'uri' => 'http://thomas-bayer.com/blz/',
));

$api = new Proxy($this->client);
$promise = $api->getBank('a');

$this->setExpectedException('RuntimeException', 'redirects');
$result = Block\await($promise, $this->loop);
}

/**
* @expectedException SoapFault
* @expectedExeptionMessage Keine Bank zur BLZ invalid gefunden!
*/
public function testBlzServiceWithInvalidBlzRejectsWithSoapFault()
{
$api = new Proxy($this->client);

$promise = $api->getBank(array('blz' => 'invalid'));

$this->setExpectedException('SoapFault', 'Keine Bank zur BLZ invalid gefunden!');
Block\await($promise, $this->loop);
}

/**
* @expectedException SoapFault
* @expectedExceptionMessage Function ("doesNotExist") is not a valid method for this service
*/
public function testBlzServiceWithInvalidMethodRejectsWithSoapFault()
{
$api = new Proxy($this->client);

$promise = $api->doesNotExist();

$this->setExpectedException('SoapFault', 'Function ("doesNotExist") is not a valid method for this service');
Block\await($promise, $this->loop);
}

/**
* @expectedException RuntimeException
* @expectedExceptionMessage cancelled
*/
public function testCancelMethodRejectsWithRuntimeException()
{
$api = new Proxy($this->client);

$promise = $api->getBank(array('blz' => '12070000'));
$promise->cancel();

$this->setExpectedException('RuntimeException', 'cancelled');
Block\await($promise, $this->loop);
}

/**
* @expectedException RuntimeException
* @expectedExceptionMessage timed out
*/
public function testTimeoutRejectsWithRuntimeException()
{
$browser = new Browser($this->loop);
Expand All @@ -191,6 +181,7 @@ public function testTimeoutRejectsWithRuntimeException()

$promise = $api->getBank(array('blz' => '12070000'));

$this->setExpectedException('RuntimeException', 'timed out');
Block\await($promise, $this->loop);
}

Expand All @@ -205,19 +196,15 @@ public function testGetLocationForFunctionNumber()
$this->assertEquals('http://www.thomas-bayer.com/axis2/services/BLZService', $this->client->getLocation(0));
}

/**
* @expectedException SoapFault
*/
public function testGetLocationOfUnknownFunctionNameFails()
{
$this->setExpectedException('SoapFault');
$this->client->getLocation('unknown');
}

/**
* @expectedException SoapFault
*/
public function testGetLocationForUnknownFunctionNumberFails()
{
$this->setExpectedException('SoapFault');
$this->assertEquals('http://www.thomas-bayer.com/axis2/services/BLZService', $this->client->getLocation(100));
}

Expand All @@ -239,15 +226,13 @@ public function testWithLocationReturnsUpdatedClient()
$this->assertEquals($original, $this->client->getLocation(0));
}

/**
* @expectedException RuntimeException
*/
public function testWithLocationInvalidRejectsWithRuntimeException()
{
$api = new Proxy($this->client->withLocation('http://nonsense.invalid'));

$promise = $api->getBank(array('blz' => '12070000'));

$this->setExpectedException('RuntimeException');
Block\await($promise, $this->loop);
}

Expand All @@ -261,6 +246,34 @@ public function testWithLocationRestoredToOriginalResolves()
$promise = $api->getBank(array('blz' => '12070000'));

$result = Block\await($promise, $this->loop);
$this->assertInternalType('object', $result);
$this->assertIsTypeObject($result);
}

public function assertIsTypeObject($actual)
{
if (method_exists($this, 'assertInternalType')) {
// legacy PHPUnit 4 - PHPUnit 7.5
$this->assertInternalType('object', $actual);
} else {
// PHPUnit 7.5+
$this->assertIsObject($actual);
}
}

public function setExpectedException($exception, $exceptionMessage = '', $exceptionCode = null)
{
if (method_exists($this, 'expectException')) {
// PHPUnit 5+
$this->expectException($exception);
if ($exceptionMessage !== '') {
$this->expectExceptionMessage($exceptionMessage);
}
if ($exceptionCode !== null) {
$this->expectExceptionCode($exceptionCode);
}
} else {
// legacy PHPUnit 4
parent::setExpectedException($exception, $exceptionMessage, $exceptionCode);
}
}
}
21 changes: 18 additions & 3 deletions tests/Protocol/ClientDecoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@

class ClientDecoderTest extends TestCase
{
/**
* @expectedException SoapFault
*/
public function testDecodeThrowsSoapFaultForInvalidResponse()
{
$decoder = new ClientDecoder(null, array('location' => '1', 'uri' => '2'));
$this->setExpectedException('SoapFault');
$decoder->decode('anything', 'invalid');
}

Expand All @@ -32,4 +30,21 @@ public function testDecodeMessageToObjectNonWsdl()

$this->assertEquals($expected, $res);
}

public function setExpectedException($exception, $exceptionMessage = '', $exceptionCode = null)
{
if (method_exists($this, 'expectException')) {
// PHPUnit 5+
$this->expectException($exception);
if ($exceptionMessage !== '') {
$this->expectExceptionMessage($exceptionMessage);
}
if ($exceptionCode !== null) {
$this->expectExceptionCode($exceptionCode);
}
} else {
// legacy PHPUnit 4
parent::setExpectedException($exception, $exceptionMessage, $exceptionCode);
}
}
}

0 comments on commit dab2f42

Please sign in to comment.