Skip to content

Commit

Permalink
Add tests for copy flag installations
Browse files Browse the repository at this point in the history
Also introduce composer test command and
alter test setup a little.
  • Loading branch information
rask committed Dec 22, 2017
1 parent 935a66d commit 6c25880
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 10 deletions.
9 changes: 6 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
composer.lock

# Stuff from tests
tests/htdocs
tests/vendor
tests/composer.lock
tests/move/htdocs
tests/copy/htdocs
tests/move/vendor
tests/copy/vendor
tests/move/composer.lock
tests/copy/composer.lock
9 changes: 6 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ before_script:

# We use the same repo straight from github because it required lesser amount of hacks
# Here we force the same current git commit id for composer
- sed -i -e "s|%%TRAVIS_COMMIT%%|$TRAVIS_COMMIT|g" tests/composer.json
- sed -i -e "s|%%TRAVIS_COMMIT%%|$TRAVIS_COMMIT|g" tests/move/composer.json
- sed -i -e "s|%%TRAVIS_COMMIT%%|$TRAVIS_COMMIT|g" tests/copy/composer.json

# Install test run into tests/ folder using tests/composer.json
- composer install --working-dir=./tests/
- composer install --working-dir=./tests/move/
- composer install --working-dir=./tests/copy/

script:
# Sanity php syntax check
Expand All @@ -31,4 +33,5 @@ script:
- composer validate composer.json

# Run the real tests finally
- "phpunit tests/*.php"
- "vendor/bin/phpunit tests/move/*.php"
- "vendor/bin/phpunit tests/copy/*.php"
6 changes: 6 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,11 @@
},
"extra": {
"class": "Koodimonni\\Composer\\Dropin"
},
"scripts": {
"test": [
"composer install --working-dir=./tests/move/ && vendor/bin/phpunit ./tests/move/*.php",
"composer install --working-dir=./tests/copy/ && vendor/bin/phpunit ./tests/copy/*.php"
]
}
}
11 changes: 10 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Build Status](https://travis-ci.org/Koodimonni/Composer-Dropin-Installer.svg?branch=master)](https://travis-ci.org/Koodimonni/Composer-Dropin-Installer) [![Latest Stable Version](https://poser.pugx.org/koodimonni/composer-dropin-installer/v/stable)](https://packagist.org/packages/koodimonni/composer-dropin-installer) [![Total Downloads](https://poser.pugx.org/koodimonni/composer-dropin-installer/downloads)](https://packagist.org/packages/koodimonni/composer-dropin-installer) [![Latest Unstable Version](https://poser.pugx.org/koodimonni/composer-dropin-installer/v/unstable)](https://packagist.org/packages/koodimonni/composer-dropin-installer) [![License](https://poser.pugx.org/koodimonni/composer-dropin-installer/license)](https://packagist.org/packages/koodimonni/composer-dropin-installer)

This composer plugin helps you to move your composer packaged files where you want them to be.
This composer plugin helps you to move or copy your composer packaged files where you want them to be.

Composer only allows you to install full directories into their own directories. There's really useful [composer/installers](https://github.com/composer/installers) for custom installation paths but it overwrites everything in folder and doesn't allow coexist of two or more projects. We just let composer install things and take it from there.

Expand Down Expand Up @@ -141,6 +141,15 @@ phpunit.xml
```
* Script requires unix filesystem (OS X,Linux)

## Testing

Run PHPUnit tests with

$ composer test

Tests are run inside the `tests/` directory where two dummy Composer projects are used to test dropin
installation methods.

##Todo
* Handle deletions on removal and on update. This could be easily done with json-database in [vendor-dir]

Expand Down
15 changes: 15 additions & 0 deletions tests/copy/KoodimonniComposerCopiedFilesExistsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

class KoodimonniComposerCopiedFilesExistsTest extends PHPUnit_Framework_TestCase
{

public function testPackageWasInstalled()
{
$this->assertFileExists(dirname( __FILE__ ) . '/htdocs/dropin-test.php');
}
public function testPackageFileExistsInVendor()
{
$this->assertFileExists(dirname( __FILE__ ) . '/vendor/dropininternal/dropin-test-package/dropin-test.php');
}

}
38 changes: 38 additions & 0 deletions tests/copy/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "koodimonni/composer-dropin-installer-tests",
"description": "composer.json for testing composer-dropin-installer",
"license": "WTFPL",
"type": "project",
"authors": [
{
"name": "Onni Hakala",
"email": "[email protected]"
}
],
"repositories": [
{
"type": "vcs",
"url": "https://github.com/Koodimonni/Composer-Dropin-Installer"
},
{
"type": "path",
"url": "../testpkg"
},
{
"packagist": false
}
],
"require": {
"koodimonni/composer-dropin-installer": "dev-master#%%TRAVIS_COMMIT%%",
"dropininternal/dropin-test-package": "dev-master"
},
"extra": {
"dropin-paths": {
"htdocs/": ["package:dropininternal/dropin-test-package"]
}
},
"config": {
"dropin-installer": "copy"
},
"minimum-stability": "dev"
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
class KoodimonniComposerFilesExistsTest extends PHPUnit_Framework_TestCase
class KoodimonniComposerMovedFilesExistsTest extends PHPUnit_Framework_TestCase
{

public function testFinnishLanguageWasInstalled()
{
$this->assertFileExists(dirname( __FILE__ ) . '/htdocs/wp-content/languages/fi.po');
Expand All @@ -11,4 +11,4 @@ public function testFinnishLanguageNotExistsInVendor()
$this->assertFileNotExists(dirname( __FILE__ ) . '/vendor/koodimonni-language/fi/fi.po');
}

}
}
File renamed without changes.
6 changes: 6 additions & 0 deletions tests/move/phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<phpunit>
<testsuite name='Dropin Installer tests'>
<directory suffix='.php'>./</directory>
</testsuite>
</phpunit>
5 changes: 5 additions & 0 deletions tests/testpkg/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "dropininternal/dropin-test-package",
"type": "library",
"version": "dev-master"
}
3 changes: 3 additions & 0 deletions tests/testpkg/dropin-test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

echo 'hello world';

0 comments on commit 6c25880

Please sign in to comment.