Skip to content

Commit

Permalink
Tests and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
RobLoach committed Mar 24, 2013
1 parent 4aa53bd commit 207b8a7
Showing 6 changed files with 55 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -7,4 +7,4 @@ php:

before_script: composer install --dev --prefer-source

script: vendor/bin/phpunit
script: phpunit
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -52,15 +52,18 @@ To set up a Component to be installed with Component Installer, have it

``` json
{
"name": "components/jquery",
"name": "components/bootstrap",
"type": "component",
"require": {
"robloach/component-installer": "*"
},
"extra": {
"component": {
"scripts": [
"jquery.js"
"js/bootstrap.js"
],
"styles": [
"css/bootstrap.css"
]
}
}
@@ -200,13 +203,13 @@ example, we define use of [html5shiv](https://github.com/aFarkas/html5shiv):
```

Todo
----
----------

* More [RequireJS Configurations](http://www.requirejs.org/docs/api.html#config)
* Put together a list of Components that make use of Component Installer
* Compile all the components into one file (`require.min.js`?)
* Determine if `scripts` is named correctly, or if it should just use `main`
* Aggregate all `styles` together into one *require.css*
* Concatenate all `scripts` into one script file and use that file for `main`
* Install Components into `vendor-dir` and symlink all scripts/styles instead?
* Determine if `component-baseurl` is the correct name for it
* Install to `components/[vendor]-[package]` rather than `components/[package]`?

3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -22,8 +22,7 @@
"kriswallsmith/assetic": "1.1.*"
},
"require-dev": {
"composer/composer": "1.0.*@dev",
"phpunit/phpunit": "3.7.*"
"composer/composer": "1.0.*@dev"
},
"minimum-stability": "alpha"
}
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
syntaxCheck="true"
bootstrap="tests/bootstrap.php"
>
<testsuites>
2 changes: 2 additions & 0 deletions src/bootstrap.php
Original file line number Diff line number Diff line change
@@ -15,9 +15,11 @@ function includeIfExists($file)
return include $file;
}
}

if ((!$loader = includeIfExists(__DIR__ . '/../vendor/autoload.php')) && (!$loader = includeIfExists(__DIR__ . '/../../../autoload.php'))) {
die('You must set up the project dependencies, run the following commands:'.PHP_EOL.
'curl -s http://getcomposer.org/installer | php'.PHP_EOL.
'php composer.phar install'.PHP_EOL);
}

return $loader;
44 changes: 42 additions & 2 deletions tests/ComponentInstaller/Test/InstallerTest.php
Original file line number Diff line number Diff line change
@@ -145,15 +145,55 @@ public function providerGetConfigOption()
*
* @dataProvider providerRequireJs
*/
public function testRequireJs(array $packages, array $config, $expected = null)
public function testRequireJs(array $json = array(), $expected = '')
{
$result = Installer::requireJs($json);
$this->assertEquals($result, $expected, sprintf('Fail to get proper expected require.js'));
}

public function providerRequireJs()
{
// Start with a base RequireJS configuration.
$js = <<<EOT
var components = %s;
if (typeof require !== "undefined" && require.config) {
require.config(components);
} else {
var require = components;
}
if (typeof exports !== "undefined" && typeof module !== "undefined") {
module.exports = components;
}
EOT;
// Tests an empty config.
$tests[] = array(
array(),
sprintf($js, "[\n\n]"),
);

// Tests a basic configuration.
$tests[] = array(
array('foo' => 'bar'),
sprintf($js, "{\n \"foo\": \"bar\"\n}"),
);

return $tests;
}

/**
* testRequireJson
*
* @dataProvider providerRequireJson
*/
public function testRequireJson(array $packages, array $config, $expected = null)
{
$configObject = new Config();
$configObject->merge(array('config' => $config));
$result = Installer::requireJson($packages, $configObject);
$this->assertEquals($result, $expected, sprintf('Fail to get proper expected require.js configuration'));
}

public function providerRequireJs()
public function providerRequireJson()
{
// Test a package that doesn't have any extra information.
$packageWithoutExtra = array(

0 comments on commit 207b8a7

Please sign in to comment.