Bitbucket pipelines with docker image using Laravel - php

I want to perform Continuous Integration using Bitbucket Pipelines to build my project.
I first used bitbucket-pipeline.yml file with default configuration as shown below:
image: php:7.1.29
pipelines:
default:
- step:
caches:
- composer
script:
- apt-get update && apt-get install -y unzip
- curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
- composer install
- vendor/bin/phpunit
After committing and running the test, it failed.
I modified the above configuration with the one below to test the database as well:
image: phpunit/phpunit:6.5.3
pipelines:
default:
- step:
caches:
- composer
script:
- apk add --no-cache php7-gd php7-xmlwriter
- php -r "file_exists('.env') || copy('.env.testing', '.env');"
- composer install
- php artisan key:generate
- php artisan migrate --seed
- vendor/bin/phpunitenter
But when I tried to run it again, it failed. I have now 8 failed builds. Can anyone help to accomplish a successful build?

Testing database or any other 3rd party application should be done using integration Test not unit test, if you're trying to test the database with a unit test it with fail for sure because you're not implemting the proper connection before running the test which should be done only with an integration test.
Also make sure to call bin/phpunit in the right directory, you should cd to the main test directory in laravel and then do ../vendor/bin/phpunit Unit.

This is where the build failed.
The problem was the composer. The composer was successfully installed but failed to run as shown in the datails below:
+ curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --
filename=composer
All settings correct for using Composer
Downloading...
Composer (version 1.9.0) successfully installed to: /usr/local/bin/composer
Use it: php /usr/local/bin/composer
+ composer install
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Your requirements could not be resolved to an installable set of packages.
Problem 1
- This package requires php ^7.2 but your PHP version (7.1.29) does not satisfy that
requirement.
Problem 2
- Installation request for moontoast/math 1.1.2 -> satisfiable by
moontoast/math[1.1.2].
- moontoast/math 1.1.2 requires ext-bcmath * -> the requested PHP extension bcmath is
missing from your system.
Problem 3
- Installation request for sebastian/type 1.1.3 -> satisfiable by
sebastian/type[1.1.3].
- sebastian/type 1.1.3 requires php ^7.2 -> your PHP version (7.1.29) does not
satisfy that requirement.
Problem 4
- doctrine/lexer 1.1.0 requires php ^7.2 -> your PHP version (7.1.29) does not
satisfy that requirement.
- doctrine/lexer 1.1.0 requires php ^7.2 -> your PHP version (7.1.29) does not
satisfy that requirement.
- Installation request for doctrine/lexer 1.1.0 -> satisfiable by
doctrine/lexer[1.1.0].
Now build succeeded when removed my previous code and tested the "Hello word" string.
as shown below:
echo "Hello world!"
<1s
Build teardown
<1s
Searching for test report files in directories named [test-results, failsafe-reports,
test-reports, surefire-reports] down to a depth of 4
Finished scanning for test reports. Found 0 test report files.
Merged test suites, total number tests is 0, with 0 failures and 0 errors.

Related

PHP Laravel error - Your requirements could not be resolved to an installable set of packages

I'm trying to create laravel project in WSL2 ubuntu. I have the projects folder (www) in the WSL root directory, inside that folder i have laravel_test subfolder. When i run
composer create-project laravel/laravel example-app
but i'm getting an error
Your requirements could not be resolved to an installable set of packages.
How can i slove this issue?
root#LAPTOP-R27NIA9B:~/www/laravel_test# composer create-project laravel/laravel example-app
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Continue as root/super user [yes]? Y
Creating a "laravel/laravel" project at "./example-app"
Installing laravel/laravel (v9.3.5)
- Installing laravel/laravel (v9.3.5): Extracting archive
Created project in /root/www/laravel_test/example-app
> #php -r "file_exists('.env') || copy('.env.example', '.env');"
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Root composer.json requires laravel/pint ^1.0 -> satisfiable by laravel/pint[v1.0.0, v1.1.0, v1.1.1].
- laravel/pint[v1.0.0, ..., v1.1.1] require ext-xml * -> it is missing from your system. Install or enable PHP's xml extension.
Problem 2
- phpunit/phpunit[9.5.10, ..., 9.5.x-dev] require ext-dom * -> it is missing from your system. Install or enable PHP's dom extension.
- Root composer.json requires phpunit/phpunit ^9.5.10 -> satisfiable by phpunit/phpunit[9.5.10, ..., 9.5.x-dev].
To enable extensions, verify that they are enabled in your .ini files:
- /etc/php/8.1/cli/php.ini
- /etc/php/8.1/cli/conf.d/10-opcache.ini
- /etc/php/8.1/cli/conf.d/10-pdo.ini
- /etc/php/8.1/cli/conf.d/20-calendar.ini
- /etc/php/8.1/cli/conf.d/20-ctype.ini
- /etc/php/8.1/cli/conf.d/20-exif.ini
- /etc/php/8.1/cli/conf.d/20-ffi.ini
- /etc/php/8.1/cli/conf.d/20-fileinfo.ini
- /etc/php/8.1/cli/conf.d/20-ftp.ini
- /etc/php/8.1/cli/conf.d/20-gettext.ini
- /etc/php/8.1/cli/conf.d/20-iconv.ini
- /etc/php/8.1/cli/conf.d/20-phar.ini
- /etc/php/8.1/cli/conf.d/20-posix.ini
- /etc/php/8.1/cli/conf.d/20-readline.ini
- /etc/php/8.1/cli/conf.d/20-shmop.ini
- /etc/php/8.1/cli/conf.d/20-sockets.ini
- /etc/php/8.1/cli/conf.d/20-sysvmsg.ini
- /etc/php/8.1/cli/conf.d/20-sysvsem.ini
- /etc/php/8.1/cli/conf.d/20-sysvshm.ini
- /etc/php/8.1/cli/conf.d/20-tokenizer.ini
You can also run `php --ini` in a terminal to see which files are used by PHP in CLI mode.
Alternatively, you can run Composer with `--ignore-platform-req=ext-xml --ignore-platform-req=ext-dom` to temporarily ignore these required extensions.
you should just install ext-xml
sudo apt-get install php-xml
laravel/pint needs this package for running correctly
my answer isn't different from Farid Saravi answer , and it solved my problem too
just want to add the answer for the second problem that appeared to me
mentioning that i'm using linux ubuntu 22.04
Problem 1
Root composer.json requires laravel/pint ^1.0 -> satisfiable by laravel/pint[v1.0.0, ..., v1.2.0].
- laravel/pint[v1.0.0, ..., v1.2.0] require ext-xml * -> it is missing from your system. Install or enable PHP's xml extension.
and its answer
sudo apt-get install php-xml
Problem 2
spatie/laravel-ignition[1.0.0, ..., 1.6.1] require ext-curl * -> it is missing from your system. Install or enable PHP's curl extension.
- Root composer.json requires spatie/laravel-ignition ^1.0 -> satisfiable by spatie/laravel-ignition[1.0.0, ..., 1.6.1].
and its answer
sudo apt-get install php-curl
First, delete the project that gave error when creating. Then
Run sudo apt-get install php8.2-curl
you can change php.8.2-curl according to the PHP version you use.
After this, create a project again. It will be successfully created

Composer install Laravel: Your requirements could not be resolved to an installable set of packages

I'm trying to install Laravel using composer for the first time.
Following the documentation on https://laravel.com/docs/5.1, I tried doing it with the command sudo composer global require "laravel/installer".
The output I got is pasted below:
Changed current directory to /home/israel/.composer
Using version ^2.0 for laravel/installer
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- laravel/installer v2.0.1 requires ext-zip * -> the requested PHP extension zip is missing from your system.
- laravel/installer v2.0.0 requires ext-zip * -> the requested PHP extension zip is missing from your system.
- Installation request for laravel/installer ^2.0 -> satisfiable by laravel/installer[v2.0.0, v2.0.1].
To enable extensions, verify that they are enabled in those .ini files:
- /etc/php/7.2/cli/php.ini
- /etc/php/7.2/cli/conf.d/10-opcache.ini
- /etc/php/7.2/cli/conf.d/10-pdo.ini
- /etc/php/7.2/cli/conf.d/15-xml.ini
- /etc/php/7.2/cli/conf.d/20-calendar.ini
- /etc/php/7.2/cli/conf.d/20-ctype.ini
- /etc/php/7.2/cli/conf.d/20-curl.ini
- /etc/php/7.2/cli/conf.d/20-dom.ini
- /etc/php/7.2/cli/conf.d/20-exif.ini
- /etc/php/7.2/cli/conf.d/20-fileinfo.ini
- /etc/php/7.2/cli/conf.d/20-ftp.ini
- /etc/php/7.2/cli/conf.d/20-gettext.ini
- /etc/php/7.2/cli/conf.d/20-iconv.ini
- /etc/php/7.2/cli/conf.d/20-json.ini
- /etc/php/7.2/cli/conf.d/20-mbstring.ini
- /etc/php/7.2/cli/conf.d/20-phar.ini
- /etc/php/7.2/cli/conf.d/20-posix.ini
- /etc/php/7.2/cli/conf.d/20-readline.ini
- /etc/php/7.2/cli/conf.d/20-shmop.ini
- /etc/php/7.2/cli/conf.d/20-simplexml.ini
- /etc/php/7.2/cli/conf.d/20-sockets.ini
- /etc/php/7.2/cli/conf.d/20-sysvmsg.ini
- /etc/php/7.2/cli/conf.d/20-sysvsem.ini
- /etc/php/7.2/cli/conf.d/20-sysvshm.ini
- /etc/php/7.2/cli/conf.d/20-tokenizer.ini
- /etc/php/7.2/cli/conf.d/20-wddx.ini
- /etc/php/7.2/cli/conf.d/20-xmlreader.ini
- /etc/php/7.2/cli/conf.d/20-xmlwriter.ini
- /etc/php/7.2/cli/conf.d/20-xsl.ini
You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.
Installation failed, deleting ./composer.json.
Does this mean PHP isn't installed?
Just run sudo apt-get install php7.2-zip && sudo apt-get install php-zip. After which you would run the command (sudo composer global require "laravel/installer") again.
It should work just fine.
It actually did. :)
If you try
sudo apt-get install php7.2-zip
and you run into the error:
sudo: apt-get: command not found
Then, try it with homebrew instead:
brew install php
This worked for me. Hopefully it saves someone a few minutes of extra head scratching :) Happy coding!
Have a look at the Laravel requirements:
PHP >= 7.1.3
OpenSSL PHP Extension
PDO PHP Extension
Mbstring PHP Extension
Tokenizer PHP Extension
XML PHP Extension
Ctype PHP Extension
JSON PHP Extension
Do you meet them? Your Error message states, that your environment does not meet the PHP version and extensions, so you have to install them first.
Once you have installed the correct PHP version and the corresponding extensions, composer will be able to install laravel as desired.
Hope this helps! :)

Cannot run artisan for laravel and issue with php version for composer

I cannot run artisan because of some weird parse error.
$ php artisan serve
Parse error: parse error, expecting "identifier (T_STRING)"' or
"variable (T_VARIABLE)"' or '{'' or '$'' in
/Library/WebServer/Documents/artisan on line 31
So I figure I need to run composer install, but then I get this:
Your requirements could not be resolved to an installable set of
packages.
Problem 1
- This package requires php >=5.5.9 but your PHP version does not satisfy that requirement. Problem 2
- classpreloader/classpreloader 2.0.0 requires php >=5.5.9 -> your PHP version does not satisfy that requirement.
- classpreloader/classpreloader 2.0.0 requires php >=5.5.9 -> your PHP version does not satisfy that requirement.
- Installation request for classpreloader/classpreloader 2.0.0 -> satisfiable by classpreloader/classpreloader[2.0.0].
So I try to install php5.5 or whatever it needs which supposedly works.
$ curl -s http://php-osx.liip.ch/install.sh | bash -s 5.5 installing...
Installing package 5.5-10.8-frontenddev into root / Package
5.5-10.8-frontenddev is already installed at version
5.5.27-20150710-221744. You wanted to install version
5.5.27-20150710-221744.
So at this point, I figure I have met the requirements, but low and behold, same issue with composer install.
No idea what's going on here because it seems like this issue has been around for some time now.
The workaround is to pass --ignore-platform-reqs to your composer command.
This should work when you can run your composer using the right version of PHP, e.g.
composer install --ignore-platform-reqs
Another way is to install on macOS different PHP version by Homebrew, e.g.
brew install php56
brew install php72
Then you can link it like:
ln -vs /usr/local/opt/php56/bin/php /usr/local/bin/php56
ln -vs /usr/local/opt/php72/bin/php /usr/local/bin/php72
then you can run composer using PHP version of your choice, e.g.
php71 composer install

cakephp 3.0 composer installation issue

After executing
php composer.phar create-project -s dev cakephp/app
I receive the following problem
Problem 1
The requested package php could not be found in any version, there may be a typo in the package name.
Problem 2
The requested package php could not be found in any version, there may be a typo in the package name.
Problem 3
Installation request for cakephp/cakephp 3.0.*-dev -> satisfiable by cakephp/cakephp[3.0.x-dev].
cakephp/cakephp 3.0.x-dev requires php >=5.4.19 -> no matching package found.
NB:
I have php 5.4.4 installed
I have composer updated to the latest commit
OS : MAC MAVRICX
The error message reads:
cakephp/cakephp 3.0.x-dev requires php >=5.4.19
But
I have php 5.4.4 installed
php 5.4.4 is not >= 5.4.19, cannot be used, and cannot be upgraded via composer hence the error output. The solution to this is to install a version of php that does satisfy that requirement.
first install php5-intl than go for composser
sudo apt-get install php5-intl
Note: This is required.
Step 1 cd /ldc/home/
Step 2 curl -s https://getcomposer.org/installer | php

Installing Sylius

I am installing Sylius. In my command prompt I did
composer create-project -s dev sylius/sylius
I get this error message :
C:\wamp\www\Symfony>composer create-project -s dev sylius/sylius
Installing sylius/sylius (dev-master 18d981683430c0afd1a102b6fc67f8ffeaabddc0)
- Installing sylius/sylius (dev-master master)
Cloning master
Created project in C:\wamp\www\Symfony\sylius
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for symfony/icu 1.2.x-dev -> satisfiable by symfony/icu[1.2.x-dev].
- symfony/icu 1.2.x-dev requires lib-icu >=4.4 -> the requested linked library icu has the wrong version installed or is missing from your system, make sure to have the extension providing it.
Problem 2
- Installation request for instaclick/php-webdriver 1.0.x-dev -> satisfiable by instaclick/php-webdriver[1.0.x-dev].
- instaclick/php-webdriver 1.0.x-dev requires ext-curl * -> the requested PHP extension curl is missing from your system.
Problem 3
- Installation request for instaclick/php-webdriver dev-master -> satisfiable by instaclick/php-webdriver[dev-master].
- instaclick/php-webdriver dev-master requires ext-curl * -> the requested PHP extension curl is missing from your system.
Problem 4
- symfony/icu 1.2.x-dev requires lib-icu >=4.4 -> the requested linked library icu has the wrong version installed or is missing from your system, make sure to have the extension providing it.
- symfony/symfony 2.3.x-dev requires symfony/icu ~1.0 -> satisfiable by symfony/icu[1.2.x-dev].
- Installation request for symfony/symfony 2.3.x-dev -> satisfiable by symfony/symfony[2.3.x-dev].
What I tried :
php composer.phar self update
php composer.phar install
Deleting sylius directory
Reinstalling sylius with the create-project command
Fresh installation of Symfony 2.3.4 and reinstallation of sylius
Did what was told in the first answer: enable extension curl and intl
Used the function get_loaded_extension() to confirm that curl and intl are loaded. Well, it is loaded
WAMP has two php.ini files, one for apache and one for CLI. When you click on WAMP tray icon in php modules you can see only modules enabled for apache, and so enabling and disabling modules takes effect only for apache copy of php.ini.
Try enabling curl and intl in X:\path\to\wamp\bin\php\php.ini which is config for CLI (BTW. config for apache is placed in X:\path\to\wamp\bin\apache\bin\php.ini).
It looks like you need to install two PHP extensions to make this work: curl and intl (which provides the lib-icu required by symfony/icu). Since you are using Windows, I recommend the official guide on how to install extensions on Windows systems. You can find the intl extension in the PECL repository here.
curl should be installed on your WAMP already, but disabled by default. See the top answer to this question for instructions on how to enable it.
Sylius has now released the latest version v1.0.0 which I have covered in a blog to install it. Here is the Source: https://www.cloudways.com/blog/install-sylius-ecommerce-framework/
You just need to run the following cammands in SSH or Terminal Sylius will be installed
$ composer create-project -s beta sylius/sylius-standard project
$ cd project
$ npm install
$ npm run gulp
$ bin/console sylius:install

Categories