simple tests and travis-ci.org support.

This commit is contained in:
Paweł Jędrzejewski 2011-12-27 20:29:48 +01:00
parent 370f78854c
commit a5b50df32f
6 changed files with 176 additions and 0 deletions

View file

@ -0,0 +1,10 @@
.buildpath
.project
.settings/
phpunit.xml
Tests/autoload.php
nbproject
vendor/
composer.phar
composer.lock

View file

@ -0,0 +1,14 @@
language: php
php:
- 5.3
- 5.4
before_script:
- wget http://getcomposer.org/composer.phar
- php composer.phar install
notifications:
email:
- travis-ci@sylius.org

View file

@ -0,0 +1,81 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\AddressingBundle\Tests\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Sylius\Bundle\AddressingBundle\DependencyInjection\SyliusAddressingExtension;
use Symfony\Component\Yaml\Parser;
class SyliusAddressingExtensionTest extends \PHPUnit_Framework_TestCase
{
/**
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
*/
public function testUserLoadThrowsExceptionUnlessDriverSet()
{
$loader = new SyliusAddressingExtension();
$config = $this->getEmptyConfig();
unset($config['driver']);
$loader->load(array($config), new ContainerBuilder());
}
/**
* @expectedException \InvalidArgumentException
*/
public function testUserLoadThrowsExceptionUnlessDriverIsValid()
{
$loader = new SyliusAddressingExtension();
$config = $this->getEmptyConfig();
$config['driver'] = 'foo';
$loader->load(array($config), new ContainerBuilder());
}
/**
* @expectedException \InvalidArgumentException
*/
public function testUserLoadThrowsExceptionUnlessEngineIsValid()
{
$loader = new SyliusAddressingExtension();
$config = $this->getEmptyConfig();
$config['engine'] = 'foo';
$loader->load(array($config), new ContainerBuilder());
}
/**
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
*/
public function testUserLoadThrowsExceptionUnlessaddressModelClassSet()
{
$loader = new SyliusAddressingExtension();
$config = $this->getEmptyConfig();
unset($config['classes']['model']['address']);
$loader->load(array($config), new ContainerBuilder());
}
/**
* getEmptyConfig
*
* @return array
*/
protected function getEmptyConfig()
{
$yaml = <<<EOF
driver: ORM
classes:
model:
address: Sylius\Bundle\AddressingBundle\Entity\DefaultAddress
EOF;
$parser = new Parser();
return $parser->parse($yaml);
}
}

View file

@ -0,0 +1,35 @@
<?php
/*
* Autoloader for tests.
*/
if (!file_exists($file = __DIR__.'/../vendor/.composer/autoload.php')) {
$vendorDir = __DIR__.'/../vendor';
require_once $vendorDir.'/symfony/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';
$loader = new \Symfony\Component\ClassLoader\UniversalClassLoader();
$loader->registerNamespaces(array(
'Symfony' => array($vendorDir.'/symfony/src', $vendorDir.'/bundles'),
'Doctrine\\Common' => $vendorDir.'/doctrine-common/lib',
'Doctrine\\DBAL' => $vendorDir.'/doctrine-dbal/lib',
'Doctrine' => $vendorDir.'/doctrine/lib',
));
$loader->register();
} else {
require_once $file;
}
spl_autoload_register(function($class) {
if (0 === strpos($class, 'Sylius\\Bundle\\AddressingBundle\\')) {
$path = __DIR__.'/../'.implode('/', array_slice(explode('\\', $class), 3)).'.php';
if (!stream_resolve_include_path($path)) {
return false;
}
require_once $path;
return true;
}
});

View file

@ -0,0 +1,16 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
if (file_exists($file = __DIR__.'/autoload.php')) {
require_once $file;
} elseif (file_exists($file = __DIR__.'/autoload.php.dist')) {
require_once $file;
}

View file

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="./Tests/bootstrap.php" color="true">
<testsuites>
<testsuite name="SyliusAddressingBundle test suite">
<directory suffix="Test.php">./Tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./</directory>
<exclude>
<directory>./Resources</directory>
<directory>./Tests</directory>
</exclude>
</whitelist>
</filter>
</phpunit>