Skip to content

Commit

Permalink
Add tests + fix PSR2
Browse files Browse the repository at this point in the history
  • Loading branch information
veewee committed Apr 21, 2016
1 parent d97c910 commit 330c9e3
Show file tree
Hide file tree
Showing 20 changed files with 252 additions and 17 deletions.
28 changes: 28 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
language: php

cache:
directories:
- $HOME/.composer/cache

matrix:
include:
- php: 5.5
- php: 5.5
env: DEPENDENCIES='low'
- php: 5.6
- php: 5.6
env: DEPENDENCIES='low'
- php: 7.0
- php: hhvm
fast_finish: true

before_install:
- composer selfupdate
- composer global require hirak/prestissimo

install:
- if [ "$DEPENDENCIES" != "low" ]; then travis_retry composer update --no-progress --profile --prefer-dist --no-scripts --no-interaction; fi;
- if [ "$DEPENDENCIES" == "low" ]; then travis_retry composer update --no-progress --profile --prefer-lowest --no-scripts --no-interaction; fi;

script:
- ./bin/grumphp run
4 changes: 2 additions & 2 deletions grumphp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ parameters:
phpcs:
standard: "PSR2"
ignore_patterns:
- "*Spec.php"
- "*Test.php"
- "spec/*Spec.php"
- "*test/*.php"
phpspec: ~
phpunit: ~
7 changes: 5 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
<listener class="PHPUnit_Util_Log_VCR" file="vendor/php-vcr/phpunit-testlistener-vcr/PHPUnit/Util/Log/VCR.php" />
</listeners>
<testsuites>
<testsuite name="Soap">
<directory>./test/PhproTest/SoapClient/Soap</directory>
<testsuite name="Unit">
<directory>./test/PhproTest/SoapClient/Unit</directory>
</testsuite>
<testsuite name="Integration">
<directory>./test/PhproTest/SoapClient/Integration</directory>
</testsuite>
</testsuites>
</phpunit>
2 changes: 1 addition & 1 deletion src/Phpro/SoapClient/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ protected function getDefaultCommands()

return $commands;
}
}
}
2 changes: 1 addition & 1 deletion src/Phpro/SoapClient/Exception/RunTimeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

class RunTimeException extends \RuntimeException
{
}
}
2 changes: 1 addition & 1 deletion src/Phpro/SoapClient/Plugin/LogPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ public static function getSubscribedEvents()
Events::FAULT => 'onClientFault'
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function add(TypeConverterInterface $converter)
}

/**
* Set (overwrite) a type converter in the collection
* Set (overwrite) a type converter in the collection
*
* @param TypeConverterInterface $converter Type converter
*
Expand Down Expand Up @@ -94,7 +94,7 @@ public function has(TypeConverterInterface $converter)

/**
* Get this collection as a typemap that can be used in PHP's \SoapClient
*
*
* @return array
*/
public function toSoapTypeMap()
Expand All @@ -105,15 +105,15 @@ public function toSoapTypeMap()
$typemap[] = [
'type_name' => $converter->getTypeName(),
'type_ns' => $converter->getTypeNamespace(),
'from_xml' => function($input) use ($converter) {
'from_xml' => function ($input) use ($converter) {
return $converter->convertXmlToPhp($input);
},
'to_xml' => function($input) use ($converter) {
'to_xml' => function ($input) use ($converter) {
return $converter->convertPhpToXml($input);
},
];
}

return $typemap;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ public function convertXmlToPhp($xml);
* @return string
*/
public function convertPhpToXml($php);
}
}
1 change: 0 additions & 1 deletion src/Phpro/SoapClient/Type/ResultProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ interface ResultProviderInterface
* @return ResultInterface
*/
public function getResult();

}
1 change: 1 addition & 0 deletions src/Phpro/SoapClient/Util/Filesystem.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

namespace Phpro\SoapClient\Util;

use Phpro\SoapClient\Exception\InvalidArgumentException;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

namespace PhproTest\SoapClient\Soap;
namespace PhproTest\SoapClient\Integration\Soap;

use Phpro\SoapClient\Soap\SoapClient as PhproSoapClient;

/**
* Class SoapClientTest
*
* @package PhproTest\SoapClient\Soap
* @package PhproTest\SoapClient\Integration\Soap
*/
class SoapClientTest extends \PHPUnit_Framework_TestCase
{
Expand Down
111 changes: 111 additions & 0 deletions test/PhproTest/SoapClient/Unit/CodeGenerator/PatcherTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?php

namespace PhproTest\SoapClient\Unit\CodeGenerator;

use Phpro\SoapClient\CodeGenerator\Patcher;
use Phpro\SoapClient\Util\Filesystem;

/**
* Class PatcherTest
*
* @package PhproTest\SoapClient\Unit\CodeGenerator
*/
class PatcherTest extends \PHPUnit_Framework_TestCase
{

/**
* @var Patcher
*/
private $patcher;

/**
* @var array
*/
private $createdFiles = array();

protected function setUp()
{
$this->patcher = new Patcher(new Filesystem());
}

protected function tearDown()
{
foreach ($this->createdFiles as $file) {
if (file_exists($file)) {
unlink($file);
}

if (file_exists($file . '.rej')) {
unlink($file . '.rej');
}
}
}

private function loadFixture($file)
{
if (!file_exists($filePath = FIXTURE_DIR . '/code-generator/' . $file)) {
throw new \RuntimeException('Could not load fixture file: ' . $filePath);
};

return file_get_contents($filePath);
}

/**
* @dataProvider patchDataProvider
* @test
*/
function it_should_patch_an_existing_file($originalContent, $newContent, $patchedContent)
{
$originalFile = $this->createdFiles[] = tempnam(sys_get_temp_dir(), 'patchtest');
$backupFile = $originalFile . '.backup';

file_put_contents($originalFile, $originalContent);
$this->patcher->patch($originalFile, $newContent);

$this->assertStringEqualsFile(
$originalFile,
$patchedContent,
sprintf('Invalid patched content in original file %s!', $originalFile)
);

if ($originalContent !== $newContent) {
$this->assertStringEqualsFile(
$backupFile,
$originalContent,
sprintf('Invalid backup file %s!', $backupFile)
);
}
}

function patchDataProvider()
{
return array(
array(
$this->loadFixture('class-default.php'),
$this->loadFixture('class-default.php'),
$this->loadFixture('class-default.php'),
),
array(
$this->loadFixture('class-default.php'),
$this->loadFixture('soap-newfield.php'),
$this->loadFixture('soap-newfield.php'),
),
array(
$this->loadFixture('class-default.php'),
$this->loadFixture('soap-removedfield.php'),
$this->loadFixture('soap-removedfield.php'),
),
array(
$this->loadFixture('class-tampered.php'),
$this->loadFixture('soap-removedfield.php'),
$this->loadFixture('patched-tampered-removedfield.php'),
),
array(
$this->loadFixture('class-tampered.php'),
$this->loadFixture('soap-removedfield.php'),
$this->loadFixture('patched-tampered-removedfield.php'),
),
);
}

}
4 changes: 3 additions & 1 deletion test/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
require_once __DIR__ . '/../vendor/autoload.php';

\VCR\VCR::configure()
->setCassettePath('test/fixtures')
->setCassettePath('test/fixtures/vcr')
->enableLibraryHooks(['soap'])
;
\VCR\VCR::turnOn();

define('FIXTURE_DIR', realpath(__DIR__ . '/fixtures'));
11 changes: 11 additions & 0 deletions test/fixtures/code-generator/class-default.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace MyNamespace;

class MyService
{
/**
* @var string
*/
protected $myField;
}
19 changes: 19 additions & 0 deletions test/fixtures/code-generator/class-tampered.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace MyNamespace;

class MyService
{
/**
* @var string
*/
protected $myField;

/**
* @return string
*/
public function getMyField()
{
return $this->myField;
}
}
24 changes: 24 additions & 0 deletions test/fixtures/code-generator/patched-tampered-newfield.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace MyNamespace;

class MyService
{
/**
* @var string
*/
protected $myField;

/**
* @var string
*/
protected $newField;

/**
* @return string
*/
public function getMyField()
{
return $this->myField;
}
}
14 changes: 14 additions & 0 deletions test/fixtures/code-generator/patched-tampered-removedfield.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace MyNamespace;

class MyService
{
/**
* @return string
*/
public function getMyField()
{
return $this->myField;
}
}
16 changes: 16 additions & 0 deletions test/fixtures/code-generator/soap-newfield.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace MyNamespace;

class MyService
{
/**
* @var string
*/
protected $myField;

/**
* @var string
*/
protected $newField;
}
7 changes: 7 additions & 0 deletions test/fixtures/code-generator/soap-removedfield.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace MyNamespace;

class MyService
{
}
File renamed without changes.

0 comments on commit 330c9e3

Please sign in to comment.