I have a website built on the Kohana framework. I see now that there exists Composer packages on packagist for the various components like core and the standard modules like auth and database.
What steps should I take to make my existing website "Composerized"?
I have lightly used Composer in other projects, but unsure what I should do in this case.
Simply install composer
http://getcomposer.org/
curl -sS https://getcomposer.org/installer | php
Run a composer init to set up a new composer file. Then go and find your package you wish to install, so for example mine looks something like this
{
"require": {
"phpunit/phpunit": "3.7.24",
"phing/phing": "dev-master",
"mailgun/mailgun-php": "dev-master",
"modulargaming/kostache": "dev-master",
"codeception/codeception": "dev-master",
"erusev/parsedown": "dev-master",
"aws/aws-sdk-php": "2.3.*"
}
}
Then just run composer install or composer update
You can then just comment out the modules in bootstrap.php
That is a very simple composer.json file, but gives you a basic idea.
Related
At the moment I use Travis CI in order to test a Symfony Bundle. PHPUnit is installed by Composer since PHPUnit is declared as a dev dependency:
{
…
"require" : {
"php": ">=5.5",
"symfony/symfony": "~2.7 || ~3.0"
},
"require-dev": {
"doctrine/orm": "^2.4.8",
"symfony/assetic-bundle": "~2.3",
"symfony/monolog-bundle": "~2.4",
"doctrine/doctrine-fixtures-bundle": "~2.3",
"liip/functional-test-bundle": "~1.4",
"phpunit/phpunit": "4.8.* || ~5.1"
},
…
}
Even if I use Travis CI's cache to cache the ~/.composer folder after each build, installing PHPUnit with Composer takes some time because PHPUnit has to check all the dependencies before installing them.
So I was thinking about using the PHAR version of PHPUnit that can be installed in one command:
wget https://phar.phpunit.de/phpunit.phar
But if I use this command on Travis CI, PHPUnit will be downloaded once in each build. Is there a way to cache this phpunit.phar file? An easy way may be to put the file in the cache, check the date of this file and download a new version if the file is older than 1 day, but there may be a simpler solution.
There is --self-update option for PHPUnit but it will be removed in the next major release.
You can configure Travis to keep certain directories between builds (called "caching" in their documentation).
Simply add the following configuration to your Travis config file and the /vendor directory should persist across builds:
cache:
directories:
- vendor
You should still include a composer install call to your build to update dependencies when the composer.json file changed. To further speed up the composer install process, you can also add you composer.lock file to version control.
Alternatively, you can of course use the same feature to simple keep a downloaded phpunit.phar file between builds.
When I use composer to install packages in my project I am only able to do so if I update my json file manually.
For example, if I run the following command in Git-Bash in my project directory (which contains my composer.phar and composer.json file):
php composer.phar require php-di/slim-bridge
It returns the following error:
[Invalid Argument Exception]
Could not find package
php-di\slim-bridge at any version for your minimum-stability (stable).
Check the package spelling or your minimum stability.
However, if i were to just update my json file to the following (example I've provided contains multiple packages I am using in my project):
{
"require": {
"slim/slim": "^3.0",
"slim/twig-view": "^2.1",
"illuminate/database": "^5.2",
"respect/validation": "^1.0",
"slim/csrf": "^0.6",
"slim/flash": "^0.1",
"phpmailer/phpmailer": "^5.2",
"php-di/slim-bridge":"^1.0"
},
"autoload":{
"psr-4": {
"App\\": "app"
}
}
}
... And I run the command: $ php.composer.phar update
Everything installs to project correctly.
What is going on that I am not able to install packages using the require method thus making me resort to manually updating my json file each time?
Since I am using windows, I used the windows installer for composer rather than install through command line and I got this working correctly. Much much easier now since I don't have to update my JSON files manually.
I am trying to install PHPUnit/Runner/Version.php using PHP composer and I get the following error.
The requested package phpunit/phpunit-runner could not be found in any version, there may be a typo in the package name.
I am not sure if I am install the wrong package or what. The following is what I have in my composer.json file.
{
"require-dev": {
"phpunit/phpunit": "4.1.*",
"phpunit/php-invoker": "*",
"phpunit/dbunit": ">=1.2",
"phpunit/phpunit-selenium": ">=1.2",
"phpunit/phpunit-story": "*",
"phpunit/phpunit-runner": "*" - with this removed that file is unavailable
}
}
Any help would be great.
The class PHPUnit_Runner_Version is part of the core PHPUnit package phpunit/phpunit in any version.
So there is no need to require it seperately because the package name you invented does not exist.
You probably have a different problem you didn't ask in this question about some software not being able to require this class, but this likely isn't being solved this way.
I installed phpunit with all dependencies:
pear install -a phpunit/phpunit
When I run a test with a failed assertion it complains it can't find PHPUnit_Extensions_Story_TestCase.
How do I fix it?
The package you are missing is pear.phpunit.de/PHPUnit_Story as you can find on the pear repository page and the GitHub repository.
PS: I found this by typing the class name into google.
PEAR installation has been deprecated, currently is better to use Composer for it, here is the PHPUnit installation guide just adding bellow lines
"require-dev": {
"phpunit/phpunit": "4.3.*",
"phpunit/phpunit-story": "*",
"phpunit/php-invoker": "*",
"phpunit/dbunit": ">=1.2",
"phpunit/phpunit-selenium": ">=1.2",
"phpunit/phpunit-story": "*"
}
or bettersudo composer global require 'phpunit/phpunit=4.3.*'
I've gotten same errors in Yii framework.
Solved it by:
1) using phpunit.phar installation(Installing PHPUnit);
2) manually added TestCase class into "autoloader" - ../tests/bootstrap.php :
if (file_exists(_YII_FRAMEWORK_PATH_.'test/PHPUnit/Extensions/Story/TestCase.php')){
require_once(_YII_FRAMEWORK_PATH_.'test/PHPUnit/Extensions/Story/TestCase.php');
}
I would like to add dependency to zendframework/zend-db package, so I added it to my composer.json:
"repositories": [
{
"type": "composer",
"url": "http://packages.zendframework.com/"
}
],
"require": {
"php": ">=5.3.2",
"symfony/class-loader": "dev-master",
"symfony/console": "dev-master",
"symfony/filesystem": "dev-master",
"symfony/finder": "dev-master",
"symfony/locale": "dev-master",
"symfony/yaml": "dev-master",
"doctrine/dbal": "dev-master",
"zendframework/zend-db": "dev-master"
}
The problem is that composer installs entire zendframework/zendframework package.
Any idea why?
as explained here http://packages.zendframework.com/#composer ZF2 now provide a composer repository with all modules.
to add the repo to you package:
"repositories": [
{
"type": "composer",
"url": "http://packages.zendframework.com/"
}
],
and from here on you can add packages seperately:
"require": {
"zendframework/zend-config": "2.0.*",
"zendframework/zend-http": "2.0.*"
},
you only need to specify the packages you want, if they have dependencies they will be resolved by compser.
allthough this does not seem to work atm...
Here's the composer.json from zend-db in the zend github. According to the file, zend-db does not have any dependencies.
This can be due to the fact that you're trying to download a package from dev-master and there's a missmatch in the composer.json of the dev-master.
I would suggest you to change the required version to something like 2.0.* and try again.
Also, Although Zend Framework is loosely coupled, in the older versions of the framework the dependencies were not explicit.
For instance, with a quick sweep over the source code of zend_db from ZEND 1.9, I found that it depends, at least, on the following packages:
Controller
Config
Filter
Json
Loader (for autoloading, I reckon this might not be necessary due to composer autoloader)
Uri
View
Wildfire
These packages might have other dependencies, hence the download size. Regardless, as King explained, Zend Framework 2.0 is different from version 1.9 and maybe this is not applicable to 2.0
Try to check if some packages have some php extensions in their dependencies. I have tried to install zend-http packages and have the same issue. Here I've found suggestion to install php_intl extension because it is required by zend-validate - subdependancy of the zend-http package. Once I've added this extension to the php.ini - problem was solved.