phpunit composer install dependicies via symlink - phpunit

I am currently installing phpunit on a per project basis.
This works extremely well, however, the install takes time because I install the directories from cache each time. Is there a way to symlink the directories to one install, or some kind of clever trick I can use to make it do that.
If I do a path repository like this, with phpunit cloned and composer installed on my disk:
"require-dev": {
"phpunit/phpunit": "dev-master"
},
"repositories": [
{
"type": "path",
"url": "../phpunit",
"options": {
"symlink": true
}
}
],
This installs only links the phpunit/phpunit directory, and not the rest of the dependencies like:
"phpunit/php-code-coverage": "^5.2",
"phpunit/php-file-iterator": "^1.4",
"phpunit/php-text-template": "^1.2",etc

Composer can install packages globally and then you can refer to the files via it's path, or put the appropriate directory into your PATH variable (in ~/.composer/vendor/bin). Another, often more popular method is to download the phpunit.phar file, and use that to run PHPunit. This also has the advantage of being a single file that can also be committed to a project - though you will want to occasionally update it to the latest version (at least within the major version, 5.7+ or 6.1+). The .Phar file can also be installed globally on the server, in the same way that composer is suggested to.

Related

How to register a local directory as a composer package

I can't figure out how to register a local directory as a composer package. I found lots of information about registering a local folder that is either a git repository or a composer package or even a zip hosted somewhere.
However I want to register a folder on my local machine, residing in the same repository as my wordpress installation (using wordplate) that is neither a git repository nor a composer package as it doesn't contain any composer.json.
What I try at the moment is to register it like this under repositories:
{
"type": "package",
"package": {
"name": "local/contact-form-7-mailchimp-extension",
"type": "wordpress-plugin",
"version": "dev-master",
"source": {
"type": "path",
"url": "resources/plugins/contact-form-7-mailchimp-extension",
"reference": "master"
}
}
}
Add "local/contact-form-7-mailchimp-extension": "*" under "require",
add "local/contact-form-7-mailchimp-extension" in "public/plugins/{$name}" under "extras" > "installer-paths".
Running composer install however doesn't install it and gives no information at all. Don't even know if it found the url or not..
Is it even possible to install a local directory like that?
You can use the path repository to install packages from a different path into your project.
However I want to register a folder on my local machine, residing in the same repository as my wordpress installation (using wordplate) that is neither a git repository nor a composer package as it doesn't contain any composer.json.
For this to work, your plugin inside the folder will need a composer.json, though. This is necessary for composer to recognize this folder as a package in the first place. Fortunately, it can be as simple as this:
{
"name": "local/contact-form-7-mailchimp-extension",
"description": "My Contact Form-extension using mailchimp",
"type": "wordpress-plugin",
"version": "dev-master"
}
Assuming the plugin is in the directory resources/plugins/contact-form-7-mailchimp-extension, you can now register this path as a repository path, meaning composer will look inside this folder for a composer.json and when your wordpress-project requires the provided package it will (by default) be symlinked into vendor.
The wordpress project's composer.json then needs these entries (the options for the repository are the defaults and can be left out, this is just to show how to disable symlinking, should you need that):
{
...,
"repositories": [
{
"type": "path",
"url":"resources/plugins/contact-form-7-mailchimp-extension",
"options": {
"symlink": true
}
}
],
"require": {
"local/contact-form-7-mailchimp-extension": "dev-master",
...
}
}
When composer installs the package, it should tell you where it installed it from, i.e. you should find the path from the repository in there.

Use Composer with Wordpress

Im trying to setup a pleasant way of working with wordpress and its plugins using composer. My question will be quite broad. How would you do it?
What i want is basically so it installs wordpress (which is now doing), but the plugins i specify get installed in a folder named "vendor" and not in the "plugins" folder. Why is that?
Here is my composer.json.
{
"name": "name",
"description": "name Wordpress",
"repositories":[
{
"type":"composer",
"url":"https://wpackagist.org"
}
],
"require": {
"timber/timber": "^1.3",
"johnpbloch/wordpress-core-installer": "^0.2.1",
"johnpbloch/wordpress": "^4.4"
},
"extra": {
"installer-paths": {
"wp-content/plugins/{$name}/": ["type:wordpress-plugin"],
"wp-content/themes/{$name}/" : ["type:wordpress-theme"]
},
"wordpress-install-dir": "wp"
}
}
I'm pretty new to this idea of using composer for package management inside WP. But I found this interesting, so I looked into it.
The installation path is specific to the plugin. Also look for wpackagist-plugin vendor name. Others will probably not put code inside the wp folder.
If you require "wpackagist-plugin/advanced-custom-fields": "^4.4" for example it is installed inside the plugins folder, as desired. The vendor prefix ('wpackagist-plugin') is important, I believe, as the packages in their search have no prefixes.
Quick solution
Try using "wpackagist-plugin/timber-library": "^1.3"
It is placed into the plugins folder nicely and comes with all it's dependencies inside the plugin folder.
Some more explanation
timber/timber is actually pulled from packagist.org (https://packagist.org/packages/timber/timber) instead of wpackagist.org.
On wpackagist.org you can find timber-library which is the packaged equivalent (includes composer autoloader and other deps).
This recipe for paths control (for plugin developers) says that:
To make use of it your extension's composer.json should contain:
"type" : "wordpress-plugin",
After you installed your packages using composer install you'll see, that the package inside of vendor/timber/timber doesn't have that type.
In fact there's an older WordPress plugin called timber, that's stuck on version 0.8. It's succeeded by timber-library.
Using "timber/timber": "^1.3" as from packagist.org
If you want to use timber as pulled from packagist.org you can do so, if you place the following line at the top of your wp-config.php:
require __DIR__ . '/wp-content/vendor/autoload.php';
Then you'll have to deploy both, the vendor and the wp folder.
There's also a discussion on GitHub about how to use vendor libraries in WP projects.
Hope you get along with that info.

How to install KnpSnappyBundle in Symfony 2.8?

I just need to install a bundle which help me to generate PDF files, but I don't know how to start to install, I don't understand the documentation, the KnpSnappyBundle's documentation says to install with composer to make:
{
"require": {
"knplabs/knp-snappy-bundle": "~1.4"
}
}
but I don't know where put such code. Nevertheless I am open to other bundle in which I can create PDF files, and please explain me step by step how to install it, I am a beginner in Symfony.
From a command line in your Symfony project folder you can run:
composer require knplabs/knp-snappy-bundle "~1.4"
And that will install the bundle for you.
I have done like below after adding it to composer.json under require
"require": {
"knplabs/knp-snappy-bundle": "dev-master"
}
After adding above run "composer update"

Using a task runner without package.json

I'm evaluating task runners, Grunt and Gulp in particular, but there's one thing I dislike about both of them: the fact that they require a package.json file for your project. This is even though your project might not even be an npm project in the first place. In my case, I'm already using composer.json, which basically does the exact same thing.
I ended up creating my package.json like this:
{
"name": "myproject",
"version": "0.0.0",
"devDependencies": {
"grunt": "~0.4.5",
"grunt-phpcs": "~0.2.3",
"grunt-phplint": "0.0.5",
"grunt-phpdocumentor": "~0.4.1"
}
}
Note that I'm not maintaining the version number, as that is unnecessary overhead. This works though, in the sense that I can run my grunt tasks after executing npm install. I feel that I should be able to do without this file though. I read that it's possible to use Grunt without a package.json, but my take is that you'd then have to install the node modules manually, which is more overhead. Gulp is no different, or at least I found no evidence to the contrary.
So the question is, are there any task runners that don't require you to define your project's metadata twice, need only a single file, and are not too bleeding edge?
Answering myself, the only thing I could find that seems to fit my requirements is bldr. It is PHP based, uses composer as package management backend, and does it without hijacking the composer.json you might already be using, as it uses bldr.json instead. It also does not require you to add metadata to the file that describes your bldr dependencies. Here's an example dependencies file (taken from http://docs.bldr.io/en/latest/blocks.html):
{
"require": {
"acme/demo-block": "#stable"
}
}
Then, when you run bldr install, your dependencies are installed and you can run your bldr tasks.

Is there an offline installer for gruntjs?

I am trying to find a way to intall gruntjs without internet access. Is there a way to download an installer? Stack overflow is giving me a hard time about the format of this question and I"m not sure what else to write. It's a pretty straightforward request.
Sort of. You'll need internet access at some point to acquire the Grunt source from Github. Grunt is a node module, and therefore needs to installed to the node_modules folder in your project. You can do this via npm, but you can also obtain the source for the module and copy it directly into the folder.
Go to: https://github.com/gruntjs/grunt to acquire the Grunt source code, and move it to your node_modules folder.
This will install grunt... but you'll still have problems. Grunt has many dependencies, listed here: https://github.com/gruntjs/grunt/blob/master/package.json
"dependencies": {
"async": "~0.1.22",
"coffee-script": "~1.3.3",
"colors": "~0.6.0-1",
"dateformat": "1.0.2-1.2.3",
"eventemitter2": "~0.4.9",
"findup-sync": "~0.1.0",
"glob": "~3.1.21",
"hooker": "~0.2.3",
"iconv-lite": "~0.2.5",
"minimatch": "~0.2.6",
"nopt": "~1.0.10",
"rimraf": "~2.0.2",
"lodash": "~0.9.0",
"underscore.string": "~2.2.0-rc",
"which": "~1.0.5",
"js-yaml": "~2.0.2",
"exit": "~0.1.0"
},
"devDependencies": {
"temporary": "~0.0.4",
"grunt-contrib-jshint": "~0.6.4",
"grunt-contrib-nodeunit": "~0.2.0",
"grunt-contrib-watch": "~0.5.3",
"grunt-contrib-bump": "git://github.com/gruntjs/grunt-contrib-bump#b9bfc07",
"difflet": "~0.2.3",
"semver": "2.1.0",
"shelljs": "~0.2.5"
}
}
Each one of these dependencies would also need to be manually installed in the same fashion into a node_modules folder inside of your projects' node_modules/grunt folder. Each of those dependencies may have dependencies of their own, so you would then have to follow the same procedure there.
Because of this, while it's technically feasible to install Grunt without using npm it's certainly not practical.
You can install node on another machine, zip up your node_modules directory and send it to yourself (email, dropbox, whatever channel you have open), and then unpack it on the machine. 7-zip compressed it to about 1.3mb for me.

Resources