From 68807e4eef1c3ec305fff9ef7ef62a75bdd3dd72 Mon Sep 17 00:00:00 2001 From: Tommy Sullivan Date: Sat, 17 May 2014 15:48:08 -0500 Subject: [PATCH] update to support Laravel 4.2, fix build --- .travis.yml | 5 ++--- composer.json | 18 +++++++++--------- src/Basset/Asset.php | 35 +++++++++++++++++++---------------- tests/Basset/AssetTest.php | 36 +++++++++++++++++++++++------------- tests/Basset/ServerTest.php | 4 ++-- 5 files changed, 55 insertions(+), 43 deletions(-) diff --git a/.travis.yml b/.travis.yml index 12ed64a..50707ed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,12 +4,11 @@ branches: only: - master -php: - - 5.3 +php: - 5.4 before_script: - curl -s http://getcomposer.org/installer | php - php composer.phar install --dev -script: phpunit \ No newline at end of file +script: phpunit diff --git a/composer.json b/composer.json index f15cae6..749ba47 100644 --- a/composer.json +++ b/composer.json @@ -14,14 +14,14 @@ "kriswallsmith/assetic": "1.1.*" }, "require-dev": { - "mockery/mockery": ">=0.7.2", - "illuminate/config": "4.0.*", - "illuminate/console": "4.0.*", - "illuminate/filesystem": "4.0.*", - "illuminate/log": "4.0.*", - "illuminate/routing": "4.0.*", - "illuminate/support": "4.0.*", - "symfony/process": "2.3.*" + "mockery/mockery": ">=0.7.2", + "illuminate/config": "4.2.*", + "illuminate/console": "4.2.*", + "illuminate/filesystem": "4.2.*", + "illuminate/log": "4.2.*", + "illuminate/routing": "4.2.*", + "illuminate/support": "4.2.*", + "symfony/process": "2.3.*" }, "suggest": { "aws/aws-sdk-php": "Deploy static assets directly to your S3 buckets.", @@ -42,4 +42,4 @@ } }, "minimum-stability": "dev" -} \ No newline at end of file +} diff --git a/src/Basset/Asset.php b/src/Basset/Asset.php index 18a21d2..8638269 100644 --- a/src/Basset/Asset.php +++ b/src/Basset/Asset.php @@ -25,7 +25,7 @@ class Asset extends Filterable { /** * Application environment. - * + * * @var string */ protected $appEnvironment; @@ -60,21 +60,21 @@ class Asset extends Filterable { /** * Assets cached last modified time. - * + * * @var int */ protected $lastModified; /** * Group the asset belongs to, either stylesheets or javascripts. - * + * * @var string */ protected $group; /** * Array of allowed asset extensions. - * + * * @var array */ protected $allowedExtensions = array( @@ -95,7 +95,7 @@ class Asset extends Filterable { public function __construct(Filesystem $files, FactoryManager $factory, $appEnvironment, $absolutePath, $relativePath) { parent::__construct(); - + $this->files = $files; $this->factory = $factory; $this->appEnvironment = $appEnvironment; @@ -125,7 +125,7 @@ public function getRelativePath() /** * Get the build path to the asset. - * + * * @return string */ public function getBuildPath() @@ -149,7 +149,7 @@ public function getBuildExtension() /** * Get the last modified time of the asset. - * + * * @return int */ public function getLastModified() @@ -258,7 +258,7 @@ public function getOrder() /** * Set the assets group. - * + * * @param string $group * @return \Basset\Asset */ @@ -286,7 +286,7 @@ public function getGroup() /** * Detect the group from the content type using cURL. - * + * * @return null|string */ protected function detectGroupFromContentType() @@ -316,7 +316,7 @@ protected function detectGroupFromContentType() /** * Detect group from the assets extension. - * + * * @return string */ protected function detectGroupFromExtension() @@ -334,7 +334,7 @@ protected function detectGroupFromExtension() /** * A raw asset is just excluded from the build process. - * + * * @return \Basset\Asset */ public function raw() @@ -346,7 +346,7 @@ public function raw() /** * Sets the asset to be served raw when the application is running in a given environment. - * + * * @param string|array $environment * @return \Basset\Asset */ @@ -364,7 +364,7 @@ public function rawOnEnvironment() /** * Determines if the asset is to be served raw. - * + * * @return bool */ public function isRaw() @@ -379,7 +379,7 @@ public function isRaw() */ public function getContent() { - return $this->files->getRemote($this->absolutePath); + return $this->files->get($this->absolutePath); } /** @@ -399,12 +399,14 @@ public function build($production = false) /** * Prepare the filters applied to the asset. - * + * * @param bool $production * @return \Illuminate\Support\Collection */ public function prepareFilters($production = false) { + + $filters = $this->filters->map(function($filter) use ($production) { $filter->setProduction($production); @@ -412,7 +414,8 @@ public function prepareFilters($production = false) return $filter->getInstance(); }); + return $filters->filter(function($filter) { return $filter instanceof FilterInterface; }); } -} \ No newline at end of file +} diff --git a/tests/Basset/AssetTest.php b/tests/Basset/AssetTest.php index 00b3827..417a304 100644 --- a/tests/Basset/AssetTest.php +++ b/tests/Basset/AssetTest.php @@ -98,14 +98,14 @@ public function testSettingCustomOrderOfAsset() public function testFiltersAreAppliedToAssets() { $this->filter->shouldReceive('make')->once()->with('FooFilter')->andReturn($filter = m::mock('Basset\Filter\Filter')); - + $filter->shouldReceive('setResource')->once()->with($this->asset)->andReturn(m::self()); $filter->shouldReceive('getFilter')->once()->andReturn('FooFilter'); $this->asset->apply('FooFilter'); $filters = $this->asset->getFilters(); - + $this->assertArrayHasKey('FooFilter', $filters->all()); $this->assertInstanceOf('Basset\Filter\Filter', $filters['FooFilter']); } @@ -124,7 +124,7 @@ public function testArrayOfFiltersAreAppliedToAssets() $this->asset->apply(array('FooFilter', 'BarFilter')); $filters = $this->asset->getFilters(); - + $this->assertArrayHasKey('FooFilter', $filters->all()); $this->assertArrayHasKey('BarFilter', $filters->all()); } @@ -149,19 +149,27 @@ public function testFiltersArePreparedCorrectly() { $fooFilter = m::mock('Basset\Filter\Filter', array(m::mock('Illuminate\Log\Writer'), 'FooFilter', array(), 'testing'))->shouldDeferMissing(); $fooFilterInstance = m::mock('stdClass, Assetic\Filter\FilterInterface'); + $fooFilterInstance->shouldReceive('getFilter')->andReturn('FooFilter'); $fooFilter->shouldReceive('getClassName')->once()->andReturn($fooFilterInstance); $barFilter = m::mock('Basset\Filter\Filter', array($barLog = m::mock('Illuminate\Log\Writer'), 'BarFilter', array(), 'testing'))->shouldDeferMissing(); - $barFilter->shouldReceive('getClassName')->once()->andReturn(m::mock('stdClass, Assetic\Filter\FilterInterface')); + $barFilterInstance = m::mock('stdClass, Assetic\Filter\FilterInterface'); + $barFilterInstance->shouldReceive('getFilter')->andReturn('BarFilter'); + $barFilter->shouldReceive('getClassName')->once()->andReturn($barFilterInstance); $bazFilter = m::mock('Basset\Filter\Filter', array($bazLog = m::mock('Illuminate\Log\Writer'), 'BazFilter', array(), 'testing'))->shouldDeferMissing(); - $bazFilter->shouldReceive('getClassName')->once()->andReturn(m::mock('stdClass, Assetic\Filter\FilterInterface')); + $bazFilterInstance = m::mock('stdClass, Assetic\Filter\FilterInterface'); + $bazFilterInstance->shouldReceive('getFilter')->andReturn('BazFilter'); + $bazFilter->shouldReceive('getClassName')->once()->andReturn($bazFilterInstance); $quxFilter = m::mock('Basset\Filter\Filter', array($quxLog = m::mock('Illuminate\Log\Writer'), 'QuxFilter', array(), 'testing'))->shouldDeferMissing(); - $quxFilter->shouldReceive('getClassName')->once()->andReturn(m::mock('stdClass, Assetic\Filter\FilterInterface')); + $quxFilterInstance = m::mock('stdClass, Assetic\Filter\FilterInterface'); + $quxFilterInstance->shouldReceive('getFilter')->andReturn('QuxFilter'); + $quxFilter->shouldReceive('getClassName')->once()->andReturn($quxFilterInstance); $vanFilter = m::mock('Basset\Filter\Filter', array(m::mock('Illuminate\Log\Writer'), 'VanFilter', array(), 'testing'))->shouldDeferMissing(); $vanFilterInstance = m::mock('stdClass, Assetic\Filter\FilterInterface'); + $vanFilterInstance->shouldReceive('getFilter')->andReturn('VanFilter'); $vanFilter->shouldReceive('getClassName')->once()->andReturn($vanFilterInstance); $this->asset->apply($fooFilter); @@ -172,11 +180,13 @@ public function testFiltersArePreparedCorrectly() $filters = $this->asset->prepareFilters(); - $this->assertTrue($filters->has('FooFilter')); - $this->assertTrue($filters->has('VanFilter')); - $this->assertFalse($filters->has('BarFilter')); - $this->assertFalse($filters->has('BazFilter')); - $this->assertFalse($filters->has('QuxFilter')); + $filterNames = $filters->map(function($f) { return $f->getFilter(); })->all(); + + $this->assertContains('FooFilter', $filterNames); + $this->assertContains('VanFilter', $filterNames); + $this->assertNotContains('BarFilter', $filterNames); + $this->assertNotContains('BazFilter', $filterNames); + $this->assertNotContains('QuxFilter', $filterNames); } @@ -199,7 +209,7 @@ public function testAssetIsBuiltCorrectly() $config = m::mock('Illuminate\Config\Repository'); - $this->files->shouldReceive('getRemote')->once()->with('path/to/public/foo/bar.sass')->andReturn($contents); + $this->files->shouldReceive('get')->once()->with('path/to/public/foo/bar.sass')->andReturn($contents); $this->asset->apply($filter); @@ -207,4 +217,4 @@ public function testAssetIsBuiltCorrectly() } -} \ No newline at end of file +} diff --git a/tests/Basset/ServerTest.php b/tests/Basset/ServerTest.php index 30cd021..d81458c 100644 --- a/tests/Basset/ServerTest.php +++ b/tests/Basset/ServerTest.php @@ -6,7 +6,7 @@ use Basset\Manifest\Manifest; use Illuminate\Routing\UrlGenerator; use Illuminate\Filesystem\Filesystem; -use Symfony\Component\Routing\RouteCollection; +use Illuminate\Routing\RouteCollection; class ServerTest extends PHPUnit_Framework_TestCase { @@ -180,4 +180,4 @@ public function testServingRawAssetsOnGivenEnvironment() } -} \ No newline at end of file +}