Skip to content

update to support Laravel 4.2 #232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
script: phpunit
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand All @@ -42,4 +42,4 @@
}
},
"minimum-stability": "dev"
}
}
35 changes: 19 additions & 16 deletions src/Basset/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Asset extends Filterable {

/**
* Application environment.
*
*
* @var string
*/
protected $appEnvironment;
Expand Down Expand Up @@ -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(
Expand All @@ -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;
Expand Down Expand Up @@ -125,7 +125,7 @@ public function getRelativePath()

/**
* Get the build path to the asset.
*
*
* @return string
*/
public function getBuildPath()
Expand All @@ -149,7 +149,7 @@ public function getBuildExtension()

/**
* Get the last modified time of the asset.
*
*
* @return int
*/
public function getLastModified()
Expand Down Expand Up @@ -258,7 +258,7 @@ public function getOrder()

/**
* Set the assets group.
*
*
* @param string $group
* @return \Basset\Asset
*/
Expand Down Expand Up @@ -286,7 +286,7 @@ public function getGroup()

/**
* Detect the group from the content type using cURL.
*
*
* @return null|string
*/
protected function detectGroupFromContentType()
Expand Down Expand Up @@ -316,7 +316,7 @@ protected function detectGroupFromContentType()

/**
* Detect group from the assets extension.
*
*
* @return string
*/
protected function detectGroupFromExtension()
Expand All @@ -334,7 +334,7 @@ protected function detectGroupFromExtension()

/**
* A raw asset is just excluded from the build process.
*
*
* @return \Basset\Asset
*/
public function raw()
Expand All @@ -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
*/
Expand All @@ -364,7 +364,7 @@ public function rawOnEnvironment()

/**
* Determines if the asset is to be served raw.
*
*
* @return bool
*/
public function isRaw()
Expand All @@ -379,7 +379,7 @@ public function isRaw()
*/
public function getContent()
{
return $this->files->getRemote($this->absolutePath);
return $this->files->get($this->absolutePath);
}

/**
Expand All @@ -399,20 +399,23 @@ 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);

return $filter->getInstance();
});


return $filters->filter(function($filter) { return $filter instanceof FilterInterface; });
}

}
}
36 changes: 23 additions & 13 deletions tests/Basset/AssetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
Expand All @@ -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());
}
Expand 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);
Expand All @@ -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);
}


Expand All @@ -199,12 +209,12 @@ 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);

$this->assertEquals('body { background-color: #fff; }', $this->asset->build());
}


}
}
4 changes: 2 additions & 2 deletions tests/Basset/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -180,4 +180,4 @@ public function testServingRawAssetsOnGivenEnvironment()
}


}
}