Travis CI & Symfony2 integration .travis.yml issue - php

I am trying to sync my Symfony2 project with Travis CI. I followed all the instructions and managed to set everything up correctly. My final hurdle is .travis.yml file which i have added under the root directory of Symfony project.
Content of my .travis.yml file:
php:
- 5.4
script:
- ./binphpunit -c app
notifications:
email:
- myemail#gmail.com
My phpunit is installed under bin/phpunit as binary
Error log:
/usr/bin/env: php No such file or directory
The command "./bin/phpunit -c app" exited with 127

Probably you miss the language specification. Try putting this:
language: php
as first line.
Double check the phpunit travis configuration, probably simply without any path.
Check an example here
Hope this help

Related

Symfony "no PHP binaries detected"

Ive been just starting to learn Symfony PHP framework, and Ive run into some problems with its configuration.
When trying to create a new project with command line like so:
symfony new --full my_project
I kept getting a simple error message:
no PHP binaries detected
and no files were created in the current folder. I searched on the net, and found out that Symfony apparently isnt able to find the location of my php.exe, despite it already being set in my system variables. And there was no information about how to properly configure this in Symfony.
How do I fix this error?
Turns out Symfony already contains functions to autodetect installed PHP versions from system variables. The command to fix the Symfony configuration is this:
symfony local:php:refresh
My next attempt to create a new project work fine after that.
Also, I suspect this error was the result of me installing PHP files after installing Symfony.
symfony local:php:refresh
doesn't always work. If your php is not in [/usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /usr/games /usr/local/games /snap/bin] and a few other locations (check with symfony local:php:list -vvv) then symfony won't find it.
I compiled my own PHP from source and installed versions 7.4.20 and 8.0.7 in /home/username/php/7.4 and /home/username/php/8.0. If I want to use my PHP 8.0.7, then I have to make a symlink because updating the $PATH doesn't help.
sudo ln -s /home/username/php/8.0/bin/php /usr/local/bin/php
This works and symfony finds it.
Follow below steps:
Step 1: download & Install xampp in your system
Step 2: open the xampp folder.
find php folder and hit enter
Step 3: copy the path and paste in your system environment
Step 4 : run
php -v
you are good to go!

vendor/bin/phpunit not working for Lumen

I'm new to Lumen (and Laravel). I've created a project with Composer and now I'm trying to get PHPUnit to work.
I'm following a book, where it should be possible to run a default passing test by typing vendor/bin/phpunit in the terminal, but it gives the error:
'vendor' is not recognized as an internal or external command,
operable program or batch file
I've checked that the phpunit file is actually there and that phpunit is added as dependency in my composer.json file. I've also tried ./vendor/bin/phpunit and vendor/bin/phpunit/phpunit, but with the same result.
I've searched Google to find a solution, but everyone else seem to have issues when running phpunit (wihout vendor/bin) and the solution is to use the full path vendor/bin/phpunit, but since I'm already doing that, it does not fix my problem.
I'm using PHPStorm on a Windows machine and running the PHP server via PHPStorm. I've not modified the default Lumen project.
Any help is greatly appreciated!
UPDATE:
Trying php vendor/bin/phpunit gives the following error:
You need to set up the project dependencies using the following
commands:
wget http://getcomposer.org/composer.phar
php composer.phar install
I'm not sure what that means, since I've already installed Composer. I used Composer to create the project and I haven't changed the dependencies from the default.
I had the same problem, for Windows it's vendor\bin\phpunit ;)
It turned out that some symlinks and permissions were not installed properly in the default project. I tried deleting the entire vendor/ directory and run composer install.
Now I can run phpunit with the command vendor\bin\phpunit (because I'm running on Windows - thanks Nizarii)
try this:
php vendor/bin/phpunit
Try putting php in front of the phpunit path like so:
php vendor/bin/phpunit

Symfony 2 doesn't generate web/bundle/framework structure

I have a huge problem with Symfony. I installed Symfony 2.7.5 from command line:
$ symfony new my_project
But the main problem is that all project was generated correctly with the exception of directory: /web/bundle
So I have in this folder two empty files (not catalogues!) with 0 KB size: framework and sensiodistribution. That means all Symfony error pages haven't any css style and look ugly.
Screens:
My local folder:
and
Error page:
What should I do?
Command:
$ app/console assets:install
populated this catalogue and it was the solution of the problem.

Symfony2 on Heroku (official buildpack) - how to dump assets?

I have a problem with Symfony assets on heroku (official php buildpack).
My code is based on Symfony 2.5 with new 3.0 folder structure, and it's using one local js and css file (the rest is loaded via cdn).
Those files are loaded exactly as described here: http://symfony.com/doc/current/cookbook/assetic/asset_management.html.
On dev environment everything is ok, but when i change env to prod then i need to do assetic:dump to force symfony dump my assets files into web/css|js folders. I made test on my local machine (switching env to prod) and everything is ok. The problem is with heroku, and its ephemeral filesystem:
When I try to run assetic:dump --env=prod by composer post-install-cmd, then deploy finish with successs, but every request ends up with:
AH01071: Got error 'PHP message: PHP Fatal error: Uncaught exception
'InvalidArgumentException' with message
'The file "/tmp/build_012d99e7-a14a-4626-afec-3ded3d4baeec/app/config/routing.yml"
When i deploy app without assetic:dump then of course my local css and js files are not available :/
Maybe there is some other script hook i can use to dump my assets?
Any ideas? Anyone succeded with assetic:dump on heroku and official php buildpack?
PHP and Symfony support has been revamped a lot in the last months, check out these links:
http://symfony.com/doc/current/cookbook/deployment/heroku.html
https://devcenter.heroku.com/articles/getting-started-with-php
https://devcenter.heroku.com/articles/php-support
https://devcenter.heroku.com/articles/getting-started-with-symfony2
What's most important:
Set an environment variable for SYMFONY_ENV
The value of SYMFONY_ENV is used to define the environment for CLI commands. So you don't have to fiddle about something like --env=prod in you custom commands. Composer hooks from composer.json (like post-install-cmd) are automatically executed with the defined environment. Please note: Set it to something different than dev. A dev environment may not work well on Heroku because Composer's dev dependencies (require-dev) are not installed. This is due to the --no-dev flag during the composer install on Heroku. For example, in the Symfony Standard Edition) the SensioGeneratorBundle never gets installed (if you do not move it to the require key in composer.json) and the dev environment won't work.
Error on /tmp path
The mentioned error should have been fixed with https://github.com/symfony/symfony/pull/12784. See also https://github.com/heroku/heroku-buildpack-php/issues/64.
Custom commands during deployment
Custom commands like assetic:dump can be placed in composer.json's script section under the compile key:
{
"scripts": {
"compile": [
"app/console assetic:dump"
]
}
}
See also https://devcenter.heroku.com/articles/php-support#custom-compile-step. Environment is taken from the above mentioned SYMFONY_ENV environment variable.

How to unittest symfony2 core

After a fresh symfony2 install i can run phpunit -c app/ and phpunit tests the included demo application: OK (1 test, 1 assertion).
But i receive no output (even with verbosity) when i run phpunit -c vendor/symfony/ as described here: http://symfony.com/doc/2.0/contributing/code/tests.html.
Does anyone know how to make this work?
PHPUnit: 3.6.2
PHP: 5.3.8
Symfony: 2.0.5
Testing twig, doctrine and other plugins works as expected (although doctrine tests fail for some reason).
If you have no output it's maybe because you configured php not to display errors.
You must install the vendors using the vendors.php script before lauching the Symfony test suite:
$ php vendor/symfony/vendors.php
Are you running the tests using the provided phpunit.xml.dist configuration file?
From your projects root directory:
$ phpunit --configuration app/phpunit.xml.dist vendor/symfony/tests
That should add an autoloader for vendors.

Categories