-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from open-sausages/pulls/1.0/tests-n-windows
BUG Fix windows support
- Loading branch information
Showing
14 changed files
with
309 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/tests/ export-ignore | ||
.gitattributes export-ignore | ||
.gitignore export-ignore | ||
.travis.yml export-ignore | ||
LICENSE export-ignore | ||
*.xml.dist export-ignore | ||
README.md export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
/vendor/ | ||
composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
language: php | ||
|
||
dist: trusty | ||
|
||
cache: | ||
directories: | ||
- $HOME/.composer/cache/files | ||
|
||
matrix: | ||
include: | ||
- php: 5.6 | ||
- php: 7.2 | ||
|
||
fast_finish: true | ||
|
||
before_script: | ||
- phpenv rehash | ||
- export PATH=~/.composer/vendor/bin:$PATH | ||
- composer validate | ||
- composer global require squizlabs/php_codesniffer:^3 --prefer-dist --no-interaction --no-progress --no-suggest -o | ||
- composer install --prefer-dist --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile | ||
|
||
script: | ||
- vendor/bin/phpunit | ||
- composer run-script lint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ruleset><rule ref="PSR2" /></ruleset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit colors="true"> | ||
<testsuite name="Default"> | ||
<directory>tests/</directory> | ||
</testsuite> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
namespace SilverStripe\VendorPlugin\Tests\Methods; | ||
|
||
use Composer\Util\Filesystem; | ||
use PHPUnit\Framework\TestCase; | ||
use RuntimeException; | ||
use SilverStripe\VendorPlugin\Methods\ChainedMethod; | ||
use SilverStripe\VendorPlugin\Methods\CopyMethod; | ||
use SilverStripe\VendorPlugin\Methods\ExposeMethod; | ||
use SilverStripe\VendorPlugin\Util; | ||
|
||
class ChainedMethodTest extends TestCase | ||
{ | ||
/** | ||
* @var Filesystem | ||
*/ | ||
protected $filesystem = null; | ||
|
||
/** | ||
* @var string app base path | ||
*/ | ||
protected $root = null; | ||
|
||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
// Get temp dir | ||
$this->root = Util::joinPaths( | ||
sys_get_temp_dir(), | ||
'ChainedMethodTest', | ||
substr(sha1(uniqid()), 0, 10) | ||
); | ||
|
||
// Setup filesystem | ||
$this->filesystem = new Filesystem(); | ||
$this->filesystem->ensureDirectoryExists($this->root); | ||
} | ||
|
||
protected function tearDown() | ||
{ | ||
$this->filesystem->remove($this->root); | ||
parent::tearDown(); | ||
} | ||
|
||
public function testFailover() | ||
{ | ||
$failingMethod = $this->createMock(CopyMethod::class); | ||
$failingMethod | ||
->method('exposeDirectory') | ||
->willThrowException(new RuntimeException()); | ||
|
||
// Create eventually successful method | ||
$method = new ChainedMethod($failingMethod, new CopyMethod()); | ||
|
||
// Expose | ||
$target = Util::joinPaths($this->root, 'resources', 'client'); | ||
$method->exposeDirectory( | ||
realpath(__DIR__.'/../fixtures/source/client'), | ||
$target | ||
); | ||
|
||
// Ensure file exists | ||
$this->assertFileExists(Util::joinPaths($this->root, 'resources', 'client', 'subfolder', 'somefile.txt')); | ||
|
||
// Folder is a real folder and not a symlink | ||
$this->assertFalse($this->filesystem->isSymlinkedDirectory($target)); | ||
$this->assertDirectoryExists($target); | ||
|
||
|
||
// Parent folder is a real folder | ||
$this->assertFalse($this->filesystem->isSymlinkedDirectory(dirname($target))); | ||
$this->assertDirectoryExists(dirname($target)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
namespace SilverStripe\VendorPlugin\Tests\Methods; | ||
|
||
use Composer\Util\Filesystem; | ||
use Composer\Util\Platform; | ||
use PHPUnit\Framework\TestCase; | ||
use SilverStripe\VendorPlugin\Methods\CopyMethod; | ||
use SilverStripe\VendorPlugin\Methods\SymlinkMethod; | ||
use SilverStripe\VendorPlugin\Util; | ||
|
||
class CopyMethodTest extends TestCase | ||
{ | ||
/** | ||
* @var Filesystem | ||
*/ | ||
protected $filesystem = null; | ||
|
||
/** | ||
* @var string app base path | ||
*/ | ||
protected $root = null; | ||
|
||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
// Get temp dir | ||
$this->root = Util::joinPaths( | ||
sys_get_temp_dir(), | ||
'CopyMethodTest', | ||
substr(sha1(uniqid()), 0, 10) | ||
); | ||
|
||
// Setup filesystem | ||
$this->filesystem = new Filesystem(); | ||
$this->filesystem->ensureDirectoryExists($this->root); | ||
} | ||
|
||
protected function tearDown() | ||
{ | ||
$this->filesystem->remove($this->root); | ||
parent::tearDown(); | ||
} | ||
|
||
public function testCopy() | ||
{ | ||
$method = new CopyMethod(); | ||
$target = Util::joinPaths($this->root, 'resources', 'client'); | ||
$method->exposeDirectory( | ||
realpath(__DIR__.'/../fixtures/source/client'), | ||
$target | ||
); | ||
|
||
// Ensure file exists | ||
$this->assertFileExists(Util::joinPaths($this->root, 'resources', 'client', 'subfolder', 'somefile.txt')); | ||
|
||
// Folder is a real folder and not a symlink | ||
$this->assertFalse($this->filesystem->isSymlinkedDirectory($target)); | ||
$this->assertDirectoryExists($target); | ||
|
||
|
||
// Parent folder is a real folder | ||
$this->assertFalse($this->filesystem->isSymlinkedDirectory(dirname($target))); | ||
$this->assertDirectoryExists(dirname($target)); | ||
} | ||
|
||
public function testRecoversFromSymlink() | ||
{ | ||
$method = new SymlinkMethod(); | ||
$target = Util::joinPaths($this->root, 'resources', 'client'); | ||
$method->exposeDirectory( | ||
realpath(__DIR__.'/../fixtures/source/client'), | ||
$target | ||
); | ||
|
||
$this->testCopy(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
namespace SilverStripe\VendorPlugin\Tests\Methods; | ||
|
||
use Composer\Util\Filesystem; | ||
use Composer\Util\Platform; | ||
use PHPUnit\Framework\TestCase; | ||
use SilverStripe\VendorPlugin\Methods\CopyMethod; | ||
use SilverStripe\VendorPlugin\Methods\SymlinkMethod; | ||
use SilverStripe\VendorPlugin\Util; | ||
|
||
class SymlinkMethodTest extends TestCase | ||
{ | ||
/** | ||
* @var Filesystem | ||
*/ | ||
protected $filesystem = null; | ||
|
||
/** | ||
* @var string app base path | ||
*/ | ||
protected $root = null; | ||
|
||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
// Get temp dir | ||
$this->root = Util::joinPaths( | ||
sys_get_temp_dir(), | ||
'SymlinkMethodTest', | ||
substr(sha1(uniqid()), 0, 10) | ||
); | ||
|
||
// Setup filesystem | ||
$this->filesystem = new Filesystem(); | ||
$this->filesystem->ensureDirectoryExists($this->root); | ||
} | ||
|
||
protected function tearDown() | ||
{ | ||
$this->filesystem->remove($this->root); | ||
parent::tearDown(); | ||
} | ||
|
||
public function testSymlink() | ||
{ | ||
$method = new SymlinkMethod(); | ||
$target = Util::joinPaths($this->root, 'resources', 'client'); | ||
$method->exposeDirectory( | ||
realpath(__DIR__.'/../fixtures/source/client'), | ||
$target | ||
); | ||
|
||
// Ensure file exists | ||
$this->assertFileExists(Util::joinPaths($this->root, 'resources', 'client', 'subfolder', 'somefile.txt')); | ||
|
||
// Folder is NOT a real folder | ||
if (Platform::isWindows()) { | ||
$this->assertTrue($this->filesystem->isJunction($target)); | ||
} else { | ||
$this->assertTrue($this->filesystem->isSymlinkedDirectory($target)); | ||
} | ||
|
||
// Parent folder is a real folder | ||
$this->assertDirectoryExists(dirname($target)); | ||
} | ||
|
||
public function testRecoversFromCopy() | ||
{ | ||
$method = new CopyMethod(); | ||
$target = Util::joinPaths($this->root, 'resources', 'client'); | ||
$method->exposeDirectory( | ||
realpath(__DIR__.'/../fixtures/source/client'), | ||
$target | ||
); | ||
|
||
// Repeat prior test | ||
$this->testSymlink(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Here is some content |