Skip to content

Commit

Permalink
Merge pull request #15 from alexander-schranz/enhancement/compatibility
Browse files Browse the repository at this point in the history
Fix phpunit tests compatibility and Symfony 5 compatibility
  • Loading branch information
jens1o committed Feb 17, 2020
2 parents 1f4911b + a7cc041 commit 3c55497
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 42 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
vendor
composer.phar
composer.lock
.phpunit.result.cache
/tests/phpunit_report/
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ before_install:
install: composer update --prefer-source $COMPOSER_FLAGS

script:
- vendor/bin/phpunit
- vendor/bin/simple-phpunit
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
],
"require": {
"php": "^5.6 || ^7.0",
"symfony/filesystem": "^2.3 || ^3.0 || ^4.0"
"symfony/filesystem": "^2.3 || ^3.0 || ^4.0 || ^5.0"
},
"require-dev": {
"phpunit/phpunit": "^5.0"
"symfony/phpunit-bridge": "^5.0.4"
},
"autoload": {
"psr-0": {
Expand Down
20 changes: 7 additions & 13 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,29 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="true"
verbose="false"
bootstrap="tests/bootstrap.php"
>
<logging>
<log type="coverage-html" target="tests/phpunit_report/report" charset="UTF-8"
yui="true" highlight="false"
<log type="coverage-html"
target="tests/phpunit_report/report"
lowUpperBound="35" highLowerBound="70"/>
</logging>

<php>
<ini name="display_errors" value="on"/>
<env name="SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT" value="true"/>
</php>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src/</directory>
</whitelist>
</filter>

<testsuites>
<testsuite name="TemporaryFilesystem tests Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<blacklist>
<directory>vendor</directory>
<directory>tests</directory>
</blacklist>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src/</directory>
</whitelist>
</filter>

</phpunit>

5 changes: 3 additions & 2 deletions tests/Neutron/TemporaryFilesystem/Tests/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
namespace Neutron\TemporaryFilesystem\Tests;

use Neutron\TemporaryFilesystem\Manager;
use PHPUnit\Framework\TestCase;

class ManagerTest extends \PHPUnit_Framework_TestCase
class ManagerTest extends TestCase
{
public function testCreateEmptyFileAndCleanScope()
{
Expand Down Expand Up @@ -288,7 +289,7 @@ public function testCreate()

private function createTmpFsMock()
{
return $this->getMock('Neutron\TemporaryFilesystem\TemporaryFilesystemInterface');
return $this->getMockBuilder('Neutron\TemporaryFilesystem\TemporaryFilesystemInterface')->getMock();
}

private function createFsMock()
Expand Down
43 changes: 19 additions & 24 deletions tests/Neutron/TemporaryFilesystem/Tests/TemporaryFilesystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace Neutron\TemporaryFilesystem\Tests;

use Neutron\TemporaryFilesystem\IOException;
use Neutron\TemporaryFilesystem\TemporaryFilesystem;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Filesystem;

class TemporaryFilesystemTest extends \PHPUnit_Framework_TestCase
class TemporaryFilesystemTest extends TestCase
{
/**
* @var string $workspace
Expand Down Expand Up @@ -88,7 +90,7 @@ public function testCreateTemporaryDirWithPrefix()
$dir = $this->filesystem->createTemporaryDirectory(0777, 200, 'neutron');
$this->assertTrue(file_exists($dir));
$this->assertTrue(is_dir($dir));
$this->assertContains('neutron', $dir);
$this->assertStringContainsString('neutron', $dir);
rmdir($dir);
}

Expand All @@ -105,53 +107,48 @@ public function provideFilesToCreate()
);
}

/**
* @expectedException Neutron\TemporaryFilesystem\IOException
*/
public function testCreateEmptyFileInvalidDir()
{
$this->expectException(IOException::class);

$createDir = $this->workspace . DIRECTORY_SEPARATOR . 'invalid-book-dir';

$this->filesystem->createEmptyFile($createDir);
}

/**
* @expectedException Neutron\TemporaryFilesystem\IOException
*/
public function testCreateEmptyFileInvalidDirSecondMethod()
{
$this->expectException(IOException::class);

$createDir = $this->workspace . DIRECTORY_SEPARATOR . 'invalid-book-dir';

$this->filesystem->createEmptyFile($createDir, 'romain', 'neutron');
}

/**
* @expectedException Neutron\TemporaryFilesystem\IOException
*/
public function testCreateEmptyFileFails()
{
$this->expectException(IOException::class);

$createDir = $this->workspace . DIRECTORY_SEPARATOR . 'book-dir';
mkdir($createDir);

$this->filesystem->createEmptyFile($createDir, 'romain', 'neutron', null, 0);
}

/**
* @expectedException Neutron\TemporaryFilesystem\IOException
*/
public function testCreateEmptyFileOnFile()
{
$this->expectException(IOException::class);

$createDir = $this->workspace . DIRECTORY_SEPARATOR . 'book-dir';
touch($createDir);

$this->filesystem->createEmptyFile($createDir, null, null, null);
}

/**
* @expectedException Neutron\TemporaryFilesystem\IOException
*/
public function testCreateEmptyFileOnFileSecondMethod()
{
$this->expectException(IOException::class);

$createDir = $this->workspace . DIRECTORY_SEPARATOR . 'book-dir';
touch($createDir);

Expand Down Expand Up @@ -180,27 +177,25 @@ public function testTemporaryFiles($prefix, $suffix, $extension, $maxTry, $patte
public function testTemporaryFile($prefix, $suffix, $extension, $maxTry, $pattern)
{
$file = $this->filesystem->createTemporaryFile($prefix, $suffix, $extension, $maxTry);
$this->assertInternalType('string', $file);
$this->assertIsString($file);

$this->assertTrue(file_exists($file));
$this->assertEquals(realpath(sys_get_temp_dir()), realpath(dirname($file)));
$this->assertEquals(0, filesize($file));
$this->assertRegExp($pattern, basename($file));
}

/**
* @expectedException Neutron\TemporaryFilesystem\IOException
*/
public function testTemporaryFilesFails()
{
$this->expectException(IOException::class);

$this->filesystem->createTemporaryFiles(3, 'prefix', 'suffix', null, 0);
}

/**
* @expectedException \InvalidArgumentException
*/
public function testTemporaryFilesInvalidQuantity()
{
$this->expectException(\InvalidArgumentException::class);

$this->filesystem->createTemporaryFiles(0);
}
}

0 comments on commit 3c55497

Please sign in to comment.