Testing with Codeception

Hi guys,

is anyone of you testing his app with codeception and uses Phalcons assets filters ?

$this->assets
 ->collection('css')
 ->addCss('css/bootstrap.min.css', false, false)
 ->addCss('css/font-awesome.min.css', false, false)
 ->addCss('css/style.css', true)
 ->setTargetPath('css/production.css')
 ->setTargetUri('css/production.css')
 ->join(true)
 ->addFilter(new \Phalcon\Assets\Filters\Cssmin());

Im trying to do functional tests but always get this error:

ErrorException: Phalcon\Assets\Resource::getContent(css/bootstrap.min.css): failed to open stream: No such file or directory

I tried to change cwd with chdir(); but no effetcs! Any experiences ? Thanks

Is no one testing with codeception or no one using this build in minifier stuff ?!?!? :D

I personally don't use it, but after looking through the docs on it... Unless your using remote resources, you should not pass false as the first param to addCss() since this tells the method weather you are using a local(true) or remote(false) resource. This, in turn, affects the rendered URI to the asset. So it should be something like,

$this->assets
 ->collection('css')
 ->addCss('css/bootstrap.min.css', true, false)
 ->addCss('css/font-awesome.min.css', true, false)
 ->addCss('css/style.css', true, true)
 ->setTargetPath('css/production.css')
 ->setTargetUri('css/production.css')
 ->join(true)
 ->addFilter(new \Phalcon\Assets\Filters\Cssmin());

http://docs.phalconphp.com/en/latest/reference/assets.html#local-remote-resources

API: http://docs.phalconphp.com/en/latest/api/Phalcon%5Assets%5Manager.html

Also note that I am still passing 'false' as the second param for your first two assets? That controls if your want to filter the resource or not. Since you are using min'd files here anyway, you shouldn't bother with it. Wear as your css/style.css is not minified, we should, so we pass true for both params here.

The docs and API are not clear has to what is the default (true or false) for any of the described methods, so I played it safe and specified for each. Hope this helps.

well I tried that, but the next Exception gets thrown:

Phalcon\Assets\Exception: Resource 'css/bootstrap.min.css' does not have a valid source path

I played around a bit, tried to prefix the path and so on ...

Maybe I change back to Gulp to minify my assets :)

THanks anyway, for your help !



7.4k

Hi, please use absolute path to the source and to the final files.

            $assets
                ->collection('headerCss')
                ->addCss('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css', false, false)
                ->addCss('https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css', false, false)
                ->addCss('https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css', false, false)
                ->addCss($config->application->backendAssets.'/plugins/jvectormap/jquery-jvectormap-1.2.2.css', true) // <- can be everywhere in your project
                ->setTargetPath($config->application->documentRoot.'/assets/css/css.minified.backend.css') // <- path to the public/webroot directory
                ->setTargetUri('p/assets/css/css.minified.backend.css')
                ->join(true)
                ->addFilter(new \Phalcon\Assets\Filters\Cssmin())
            ;