Skip to content

Commit

Permalink
Merge pull request #112 from alchemy-fr/clean/teleporters
Browse files Browse the repository at this point in the history
Clean up teleporters and tests
  • Loading branch information
aztech-dev authored Aug 5, 2016
2 parents 28b7c0e + 8fe9da3 commit b0316a0
Show file tree
Hide file tree
Showing 24 changed files with 136 additions and 121 deletions.
3 changes: 2 additions & 1 deletion src/Resource/Teleporter/AbstractTeleporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
* Class AbstractTeleporter
* @package Alchemy\Zippy\Resource\Teleporter
*
* @deprecated Typehint against TeleporterInterface instead and use GenericTeleporter with custom reader/writers instead.
* @deprecated Typehint against TeleporterInterface instead and use GenericTeleporter
* with custom reader/writers instead. This class will be removed in v0.5.x
*/
abstract class AbstractTeleporter implements TeleporterInterface
{
Expand Down
18 changes: 7 additions & 11 deletions src/Resource/Teleporter/GuzzleTeleporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,31 @@

namespace Alchemy\Zippy\Resource\Teleporter;

use Alchemy\Zippy\Resource\Reader\Guzzle\LegacyGuzzleReaderFactory;
use Alchemy\Zippy\Resource\Reader\Guzzle\GuzzleReaderFactory;
use Alchemy\Zippy\Resource\ResourceLocator;
use Alchemy\Zippy\Resource\ResourceReaderFactory;
use Alchemy\Zippy\Resource\Writer\FilesystemWriter;
use GuzzleHttp\Client;

/**
* Guzzle Teleporter implementation for HTTP resources
*
* @deprecated Use \Alchemy\Zippy\Resource\GenericTeleporter instead. This class will be removed in v0.5.x
*/
class GuzzleTeleporter extends GenericTeleporter
{
/**
* @param Client $client
* @param ResourceReaderFactory $readerFactory
* @param ResourceLocator $resourceLocator
*/
public function __construct(
Client $client = null,
ResourceReaderFactory $readerFactory = null,
ResourceLocator $resourceLocator = null
) {
parent::__construct($readerFactory ?: new LegacyGuzzleReaderFactory($client), new FilesystemWriter(),
$resourceLocator);
public function __construct(ResourceReaderFactory $readerFactory = null, ResourceLocator $resourceLocator = null)
{
parent::__construct($readerFactory ?: new GuzzleReaderFactory(), new FilesystemWriter(), $resourceLocator);
}

/**
* Creates the GuzzleTeleporter
*
* @deprecated
* @deprecated This method will be removed in v0.5.x
* @return GuzzleTeleporter
*/
public static function create()
Expand Down
2 changes: 2 additions & 0 deletions src/Resource/Teleporter/LegacyGuzzleTeleporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

/**
* Guzzle Teleporter implementation for HTTP resources
*
* @deprecated Use \Alchemy\Zippy\Resource\GenericTeleporter instead. This class will be removed in v0.5.x
*/
class LegacyGuzzleTeleporter extends GenericTeleporter
{
Expand Down
3 changes: 2 additions & 1 deletion src/Resource/Teleporter/LocalTeleporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use Symfony\Component\Filesystem\Filesystem;

/**
* This class transport an object using the local filesystem
* This class transports an object using the local filesystem
*/
class LocalTeleporter extends AbstractTeleporter
{
Expand Down Expand Up @@ -73,6 +73,7 @@ public function teleport(ZippyResource $resource, $context)
* Creates the LocalTeleporter
*
* @return LocalTeleporter
* @deprecated This method will be removed in a future release (0.5.x)
*/
public static function create()
{
Expand Down
1 change: 1 addition & 0 deletions src/Resource/Teleporter/StreamTeleporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function __construct()
* Creates the StreamTeleporter
*
* @return StreamTeleporter
* @deprecated This method will be removed in a future release (0.5.x)
*/
public static function create()
{
Expand Down
19 changes: 13 additions & 6 deletions src/Resource/TeleporterContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@

use Alchemy\Zippy\Exception\InvalidArgumentException;
use Alchemy\Zippy\Resource\Reader\Guzzle\GuzzleReaderFactory;
use Alchemy\Zippy\Resource\Reader\Guzzle\LegacyGuzzleReaderFactory;
use Alchemy\Zippy\Resource\Resource as ZippyResource;
use Alchemy\Zippy\Resource\Teleporter\GuzzleTeleporter;
use Alchemy\Zippy\Resource\Teleporter\GenericTeleporter;
use Alchemy\Zippy\Resource\Teleporter\LocalTeleporter;
use Alchemy\Zippy\Resource\Teleporter\StreamTeleporter;
use Alchemy\Zippy\Resource\Teleporter\TeleporterInterface;
use Alchemy\Zippy\Resource\Writer\FilesystemWriter;
use Symfony\Component\Filesystem\Filesystem;

/**
* A container of TeleporterInterface
Expand Down Expand Up @@ -85,25 +88,29 @@ public static function load()
$container = new static();

$container->factories['stream-teleporter'] = function () {
return StreamTeleporter::create();
return new StreamTeleporter();
};

$container->factories['local-teleporter'] = function () {
return LocalTeleporter::create();
return new LocalTeleporter(new Filesystem());
};

if (class_exists('GuzzleHttp\Client')) {
$container->factories['guzzle-teleporter'] = function () {
return new GuzzleTeleporter(
null,
return new GenericTeleporter(
new GuzzleReaderFactory(),
new FilesystemWriter(),
new ResourceLocator()
);
};
}
elseif (class_exists('Guzzle\Http\Client')) {
$container->factories['guzzle-teleporter'] = function () {
return new GuzzleTeleporter();
return new GenericTeleporter(
new LegacyGuzzleReaderFactory(),
new FilesystemWriter(),
new ResourceLocator()
);
};
}

Expand Down
31 changes: 19 additions & 12 deletions tests/Tests/Adapter/BSDTar/BSDTarAdapterWithOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private function provideAdapter()
{
$classname = static::getAdapterClassName();

$inflator = $this->getMockBuilder('Alchemy\Zippy\ProcessBuilder\ProcessBuilderFactory')
$inflator = $this->getMockBuilder('\Alchemy\Zippy\ProcessBuilder\ProcessBuilderFactory')
->disableOriginalConstructor()
->setMethods(array('useBinary'))
->getMock();
Expand Down Expand Up @@ -71,19 +71,26 @@ protected function provideSupportedAdapter()
public function testNewinstance()
{
$classname = static::getAdapterClassName();
$finder = $this->getMockBuilder('Symfony\Component\Process\ExecutableFinder')
$finder = $this->getMockBuilder('\Symfony\Component\Process\ExecutableFinder')
->disableOriginalConstructor()
->getMock();
$manager = $this->getMockBuilder('Alchemy\Zippy\Resource\ResourceManager')
$manager = $this->getMockBuilder('\Alchemy\Zippy\Resource\ResourceManager')
->disableOriginalConstructor()
->getMock();
$instance = $classname::newInstance($finder, $manager, $this->getMock('Alchemy\Zippy\ProcessBuilder\ProcessBuilderFactoryInterface'), $this->getMock('Alchemy\Zippy\ProcessBuilder\ProcessBuilderFactoryInterface'));

$instance = $classname::newInstance(
$finder,
$manager,
$this->getMockBuilder('\Alchemy\Zippy\ProcessBuilder\ProcessBuilderFactoryInterface')->getMock(),
$this->getMockBuilder('\Alchemy\Zippy\ProcessBuilder\ProcessBuilderFactoryInterface')->getMock()
);

$this->assertInstanceOf($classname, $instance);
}

public function testCreateNoFiles()
{
$mockedProcessBuilder = $this->getMock('Symfony\Component\Process\ProcessBuilder');
$mockedProcessBuilder = $this->getMockBuilder('\Symfony\Component\Process\ProcessBuilder')->getMock();

$mockedProcessBuilder
->expects($this->at(0))
Expand Down Expand Up @@ -135,7 +142,7 @@ public function testCreateNoFiles()

public function testCreate()
{
$mockedProcessBuilder = $this->getMock('Symfony\Component\Process\ProcessBuilder');
$mockedProcessBuilder = $this->getMockBuilder('\Symfony\Component\Process\ProcessBuilder')->getMock();

$mockedProcessBuilder
->expects($this->at(0))
Expand Down Expand Up @@ -198,7 +205,7 @@ public function testListMembers()
{
$resource = $this->getResource(self::$tarFile);

$mockedProcessBuilder = $this->getMock('Symfony\Component\Process\ProcessBuilder');
$mockedProcessBuilder = $this->getMockBuilder('\Symfony\Component\Process\ProcessBuilder')->getMock();

$mockedProcessBuilder
->expects($this->at(0))
Expand Down Expand Up @@ -243,7 +250,7 @@ public function testAddFile()

public function testgetVersion()
{
$mockedProcessBuilder = $this->getMock('Symfony\Component\Process\ProcessBuilder');
$mockedProcessBuilder = $this->getMockBuilder('\Symfony\Component\Process\ProcessBuilder')->getMock();

$mockedProcessBuilder
->expects($this->at(0))
Expand All @@ -265,7 +272,7 @@ public function testExtract()
{
$resource = $this->getResource(self::$tarFile);

$mockedProcessBuilder = $this->getMock('Symfony\Component\Process\ProcessBuilder');
$mockedProcessBuilder = $this->getMockBuilder('\Symfony\Component\Process\ProcessBuilder')->getMock();

$mockedProcessBuilder
->expects($this->at(0))
Expand Down Expand Up @@ -301,7 +308,7 @@ public function testExtractWithExtractDirPrecised()
{
$resource = $this->getResource(self::$tarFile);

$mockedProcessBuilder = $this->getMock('Symfony\Component\Process\ProcessBuilder');
$mockedProcessBuilder = $this->getMockBuilder('\Symfony\Component\Process\ProcessBuilder')->getMock();

$mockedProcessBuilder
->expects($this->at(0))
Expand Down Expand Up @@ -359,7 +366,7 @@ public function testRemoveMembers()
{
$resource = $this->getResource(self::$tarFile);

$mockedProcessBuilder = $this->getMock('Symfony\Component\Process\ProcessBuilder');
$mockedProcessBuilder = $this->getMockBuilder('\Symfony\Component\Process\ProcessBuilder')->getMock();

$mockedProcessBuilder
->expects($this->at(0))
Expand Down Expand Up @@ -396,7 +403,7 @@ public function testRemoveMembers()
->method('getProcess')
->will($this->returnValue($this->getSuccessFullMockProcess()));

$archiveFileMock = $this->getMock('Alchemy\Zippy\Archive\MemberInterface');
$archiveFileMock = $this->getMockBuilder('\Alchemy\Zippy\Archive\MemberInterface')->getMock();
$archiveFileMock
->expects($this->any())
->method('getLocation')
Expand Down
21 changes: 10 additions & 11 deletions tests/Tests/Adapter/BSDTar/TarBSDTarAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function setUp()

private function provideAdapter()
{
$inflator = $this->getMockBuilder('Alchemy\Zippy\ProcessBuilder\ProcessBuilderFactory')
$inflator = $this->getMockBuilder('\Alchemy\Zippy\ProcessBuilder\ProcessBuilderFactory')
->disableOriginalConstructor()
->setMethods(array('useBinary'))
->getMock();
Expand Down Expand Up @@ -68,8 +68,7 @@ protected function provideSupportedAdapter()

public function testCreateNoFiles()
{
$mockedProcessBuilder = $this->getMock('Symfony\Component\Process\ProcessBuilder');

$mockedProcessBuilder = $this->getMockBuilder('\Symfony\Component\Process\ProcessBuilder')->getMock();

$mockedProcessBuilder
->expects($this->at(0))
Expand Down Expand Up @@ -117,7 +116,7 @@ public function testCreate()
{
$outputParser = ParserFactory::create(TarBSDTarAdapter::getName());
$manager = $this->getResourceManagerMock(__DIR__, array('lalalalala'));
$mockedProcessBuilder = $this->getMock('Symfony\Component\Process\ProcessBuilder');
$mockedProcessBuilder = $this->getMockBuilder('\Symfony\Component\Process\ProcessBuilder')->getMock();

$mockedProcessBuilder
->expects($this->at(0))
Expand Down Expand Up @@ -169,7 +168,7 @@ public function testListMembers()
{
$resource = $this->getResource(self::$tarFile);

$mockedProcessBuilder = $this->getMock('Symfony\Component\Process\ProcessBuilder');
$mockedProcessBuilder = $this->getMockBuilder('\Symfony\Component\Process\ProcessBuilder')->getMock();

$mockedProcessBuilder
->expects($this->at(0))
Expand Down Expand Up @@ -203,7 +202,7 @@ public function testAddFile()
{
$resource = $this->getResource(self::$tarFile);

$mockedProcessBuilder = $this->getMock('Symfony\Component\Process\ProcessBuilder');
$mockedProcessBuilder = $this->getMockBuilder('\Symfony\Component\Process\ProcessBuilder')->getMock();

$mockedProcessBuilder
->expects($this->at(0))
Expand All @@ -229,7 +228,7 @@ public function testAddFile()

public function testgetVersion()
{
$mockedProcessBuilder = $this->getMock('Symfony\Component\Process\ProcessBuilder');
$mockedProcessBuilder = $this->getMockBuilder('\Symfony\Component\Process\ProcessBuilder')->getMock();

$mockedProcessBuilder
->expects($this->at(0))
Expand All @@ -251,7 +250,7 @@ public function testExtract()
{
$resource = $this->getResource(self::$tarFile);

$mockedProcessBuilder = $this->getMock('Symfony\Component\Process\ProcessBuilder');
$mockedProcessBuilder = $this->getMockBuilder('\Symfony\Component\Process\ProcessBuilder')->getMock();

$mockedProcessBuilder
->expects($this->at(0))
Expand Down Expand Up @@ -281,7 +280,7 @@ public function testExtractWithExtractDirPrecised()
{
$resource = $this->getResource(self::$tarFile);

$mockedProcessBuilder = $this->getMock('Symfony\Component\Process\ProcessBuilder');
$mockedProcessBuilder = $this->getMockBuilder('\Symfony\Component\Process\ProcessBuilder')->getMock();

$mockedProcessBuilder
->expects($this->at(0))
Expand Down Expand Up @@ -333,7 +332,7 @@ public function testRemoveMembers()
{
$resource = $this->getResource(self::$tarFile);

$mockedProcessBuilder = $this->getMock('Symfony\Component\Process\ProcessBuilder');
$mockedProcessBuilder = $this->getMockBuilder('\Symfony\Component\Process\ProcessBuilder')->getMock();

$mockedProcessBuilder
->expects($this->at(0))
Expand Down Expand Up @@ -364,7 +363,7 @@ public function testRemoveMembers()
->method('getProcess')
->will($this->returnValue($this->getSuccessFullMockProcess()));

$archiveFileMock = $this->getMock('Alchemy\Zippy\Archive\MemberInterface');
$archiveFileMock = $this->getMockBuilder('\Alchemy\Zippy\Archive\MemberInterface')->getMock();

$archiveFileMock
->expects($this->any())
Expand Down
Loading

0 comments on commit b0316a0

Please sign in to comment.