Skip to content

Commit

Permalink
Merge pull request #17 from Vinelab/tests/missed-tests
Browse files Browse the repository at this point in the history
-  fix the reading of the config file.
- write unit tests for all the classes.
- add validator classes and make them extends main validator
  • Loading branch information
Mulkave committed Sep 9, 2014
2 parents 713ef6a + e8d6676 commit ecb7045
Show file tree
Hide file tree
Showing 23 changed files with 608 additions and 57 deletions.
26 changes: 13 additions & 13 deletions src/Vinelab/Cdn/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Asset implements AssetInterface{
*
* @var array
*/
private $default_include = [
protected $default_include = [
'directories' => ['public'],
'extensions' => [],
'patterns' => [],
Expand All @@ -29,7 +29,7 @@ class Asset implements AssetInterface{
*
* @var array
*/
private $default_exclude = [
protected $default_exclude = [
'directories' => [],
'files' => [],
'extensions' => [],
Expand All @@ -40,40 +40,40 @@ class Asset implements AssetInterface{
/**
* @var Array
*/
public $included_directories;
protected $included_directories;
/**
* @var Array
*/
public $included_files;
protected $included_files;
/**
* @var Array
*/
public $included_extensions;
protected $included_extensions;
/**
* @var Array
*/
public $included_patterns;
protected $included_patterns;

/**
* @var Array
*/
public $excluded_directories;
protected $excluded_directories;
/**
* @var Array
*/
public $excluded_files;
protected $excluded_files;
/**
* @var Array
*/
public $excluded_extensions;
protected $excluded_extensions;
/**
* @var Array
*/
public $excluded_patterns;
protected $excluded_patterns;
/*
* @var boolean
*/
public $exclude_hidden;
protected $exclude_hidden;

/*
* Allowed assets for upload (found in included_directories)
Expand Down Expand Up @@ -113,7 +113,7 @@ public function init($configurations = array())
*
* @param $configurations
*/
public function parseAndFillConfiguration($configurations)
private function parseAndFillConfiguration($configurations)
{
$this->default_include = isset($configurations['include']) ?
array_merge($this->default_include, $configurations['include']) : $this->default_include;
Expand Down Expand Up @@ -179,7 +179,7 @@ public function getExcludedPatterns()
}

/**
* @return mixed
* @return Collection
*/
public function getAssets()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Vinelab/Cdn/Cdn.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function push()
// return an instance of the corresponding Provider concrete according to the configuration
$provider = $this->provider_factory->create($configurations);

$provider->upload($this->asset_holder->getAssets());
return $provider->upload($this->asset_holder->getAssets());
}

}
25 changes: 21 additions & 4 deletions src/Vinelab/Cdn/CdnFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@
use Vinelab\Cdn\Contracts\ProviderFactoryInterface;
use Vinelab\Cdn\Contracts\CdnFacadeInterface;
use Vinelab\Cdn\Contracts\CdnHelperInterface;
use Vinelab\Cdn\Validators\CdnFacadeValidator;
use Vinelab\Cdn\Exceptions\EmptyPathException;

/**
* Class CdnFacade
* @package Vinelab\Cdn
*/
class CdnFacade implements CdnFacadeInterface{

/**
* @var Contracts\ProviderFactoryInterface
*/
protected $provider_factory;

/**
* @var instance of the default provider object
*/
Expand All @@ -24,20 +31,28 @@ class CdnFacade implements CdnFacadeInterface{
*/
protected $helper;

/**
* @var Validators\CdnFacadeValidator
*/
protected $cdn_facade_validator;

/**
* Calls the provider initializer
*
* @param ProviderFactoryInterface $provider_factory
* @param Contracts\CdnHelperInterface $helper
* @param Validators\CdnFacadeValidator $cdn_facade_validator
*
* @internal param \Vinelab\Cdn\Repository $configurations
*/
public function __construct(
ProviderFactoryInterface $provider_factory,
CdnHelperInterface $helper
CdnHelperInterface $helper,
CdnFacadeValidator $cdn_facade_validator
) {
$this->provider_factory = $provider_factory;
$this->helper = $helper;
$this->cdn_facade_validator = $cdn_facade_validator;

$this->init();
}
Expand All @@ -49,10 +64,14 @@ public function __construct(
*
* @param $path
*
* @return string
* @return mixed
* @throws Exceptions\EmptyPathException
*/
public function asset($path)
{
if ( ! isset($path))
throw new EmptyPathException('Path does not exist.');

// remove slashes from begging and ending of the path then call the
// url generator of the provider
return $this->provider->urlGenerator($this->cleanPath($path));
Expand Down Expand Up @@ -85,6 +104,4 @@ private function init()
$this->provider = $this->provider_factory->create($configurations);
}



}
3 changes: 3 additions & 0 deletions src/Vinelab/Cdn/CdnHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public function __construct(Repository $configurations)
/**
* Check if the config file exist and return it or
* throw an exception
*
* @return array
* @throws Exceptions\MissingConfigurationFileException
*/
public function getConfigurations()
{
Expand Down
16 changes: 14 additions & 2 deletions src/Vinelab/Cdn/CdnServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,18 @@ public function register()
);

$this->app->bind(
'Vinelab\Cdn\Validators\Contracts\ConfigurationsInterface',
'Vinelab\Cdn\Validators\Configurations'
'Vinelab\Cdn\Validators\Contracts\ProviderValidatorInterface',
'Vinelab\Cdn\Validators\ProviderValidator'
);

$this->app->bind(
'Vinelab\Cdn\Validators\Contracts\CdnFacadeValidatorInterface',
'Vinelab\Cdn\Validators\CdnFacadeValidator'
);

$this->app->bind(
'Vinelab\Cdn\Validators\Contracts\ValidatorInterface',
'Vinelab\Cdn\Validators\Validator'
);

// register the commands:
Expand Down Expand Up @@ -106,6 +116,8 @@ public function register()
});


// registering the package (for the config files)
$this->package("vinelab/cdn");

}

Expand Down
1 change: 0 additions & 1 deletion src/Vinelab/Cdn/Contracts/AssetInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
interface AssetInterface {

public function init($configurations);
public function parseAndFillConfiguration($configurations);

public function getIncludedDirectories();
public function getIncludedExtensions();
Expand Down
1 change: 1 addition & 0 deletions src/Vinelab/Cdn/Exceptions/Exceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ class CdnException extends \RuntimeException {}
class MissingConfigurationFileException extends CdnException {}
class MissingConfigurationException extends CdnException {}
class UnsupportedProviderException extends CdnException {}
class EmptyPathException extends CdnException {}

2 changes: 1 addition & 1 deletion src/Vinelab/Cdn/Finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private function includeThis(AssetInterface $asset_holder)

// include files with this extensions
foreach ($asset_holder->getIncludedExtensions() as $extension) {
$this->name('*'.$extension);
$this->name('*' . $extension);
}

// include patterns
Expand Down
Loading

0 comments on commit ecb7045

Please sign in to comment.