Skip to content

Commit 7a8e925

Browse files
committed
Merge pull request #25 from symfony-cmf/test_tests
Added test files and readies for travis integration
2 parents 45788d0 + fa7315c commit 7a8e925

File tree

5 files changed

+148
-2
lines changed

5 files changed

+148
-2
lines changed

.travis.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
language: php
2+
3+
php:
4+
- 5.3
5+
- 5.4
6+
- 5.5
7+
8+
env:
9+
- SYMFONY_VERSION=2.2.*
10+
- SYMFONY_VERSION=2.3.*
11+
- SYMFONY_VERSION=dev-master
12+
13+
before_script:
14+
- composer self-update
15+
- composer require symfony/symfony:${SYMFONY_VERSION} --prefer-source
16+
17+
script: phpunit --coverage-text
18+
19+
notifications:
20+
irc: "irc.freenode.org#symfony-cmf"
21+
22+
23+
matrix:
24+
allow_failures:
25+
- env: SYMFONY_VERSION=dev-master

phpunit.xml.dist

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html -->
4+
<phpunit
5+
colors="true"
6+
bootstrap="tests/bootstrap.php"
7+
>
8+
9+
<testsuites>
10+
<testsuite name="Symfony CmfMenuBundle Test Suite">
11+
<directory>./tests</directory>
12+
</testsuite>
13+
</testsuites>
14+
15+
</phpunit>

tests/Functional/BaseTestCaseTest.php

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
3+
namespace Tests\Functional;
4+
5+
use Symfony\Cmf\Component\Testing\HttpKernel\TestKernel;
6+
use Symfony\Component\Config\Loader\LoaderInterface;
7+
8+
class BaseTestCaseTest extends \PHPUnit_Framework_TestCase
9+
{
10+
public function setUp()
11+
{
12+
$me = $this;
13+
14+
$this->tc = $this->getMockBuilder(
15+
'Symfony\Cmf\Component\Testing\Functional\BaseTestCase'
16+
)->setMethods(array(
17+
'createKernel',
18+
))->getMockForAbstractClass();
19+
20+
$this->container = $this->getMock(
21+
'Symfony\Component\DependencyInjection\ContainerInterface'
22+
);
23+
24+
$this->kernel = $this->getMock(
25+
'Symfony\Component\HttpKernel\KernelInterface'
26+
);
27+
28+
$this->client = $me->getMockBuilder(
29+
'Symfony\Bundle\FrameworkBundle\Client'
30+
)->disableOriginalConstructor()->getMock();
31+
32+
$this->container->expects($this->any())
33+
->method('get')
34+
->will($this->returnCallback(function ($name) use ($me) {
35+
$dic = array(
36+
'test.client' => $me->client
37+
);
38+
39+
return $dic[$name];
40+
}));
41+
42+
$this->kernel->expects($this->any())
43+
->method('getContainer')
44+
->will($this->returnValue($this->container));
45+
46+
$tc = $this->tc;
47+
$tc::staticExpects($this->any())
48+
->method('createKernel')
49+
->will($this->returnValue($this->kernel));
50+
51+
$this->client->expects($this->any())
52+
->method('getContainer')
53+
->will($this->returnValue($this->container));
54+
55+
}
56+
57+
public function testGetContainer()
58+
{
59+
$res = $this->tc->getContainer();
60+
$this->assertEquals($this->container, $res);
61+
}
62+
63+
public function provideTestDb()
64+
{
65+
return array(
66+
array('PHPCR', 'PHPCR'),
67+
array('Phpcr', 'PHPCR'),
68+
array('ORM', 'ORM'),
69+
array('foobar', null),
70+
);
71+
}
72+
73+
/**
74+
* @dataProvider provideTestDb
75+
* @depends testGetContainer
76+
*/
77+
public function testDb($dbName, $expected)
78+
{
79+
if (null === $expected) {
80+
$this->setExpectedException('InvalidArgumentException',
81+
$dbName.'" does not exist'
82+
);
83+
}
84+
85+
$res = $this->tc->getDbManager($dbName);
86+
87+
$className = sprintf(
88+
'Symfony\Cmf\Component\Testing\Functional\DbManager\%s',
89+
$expected
90+
);
91+
92+
$this->assertInstanceOf($className, $res);
93+
}
94+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Symfony\Cmf\Component\Testing\Tests\HttpKernel;
3+
namespace Tests\HttpKernel;
44

55
use Symfony\Cmf\Component\Testing\HttpKernel\TestKernel;
66
use Symfony\Component\Config\Loader\LoaderInterface;
@@ -24,7 +24,7 @@ public function testBundleSetRequire()
2424
'default', 'phpcr_odm'
2525
));
2626
$bundles = $this->kernel->registerBundles();
27-
$this->assertCount(5, $bundles);
27+
$this->assertCount(6, $bundles);
2828
}
2929

3030
public function testBundleAdd()

tests/bootstrap.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
$vendorDir = realpath(__DIR__.'/../vendor');
4+
5+
if (!$loader = include $vendorDir.'/autoload.php') {
6+
$nl = PHP_SAPI === 'cli' ? PHP_EOL : '<br />';
7+
echo "$nl$nl";
8+
die('You must set up the project dependencies.'.$nl.
9+
'Run the following commands in '.dirname(__DIR__).':'.$nl.$nl.
10+
'curl -s http://getcomposer.org/installer | php'.$nl.
11+
'php composer.phar install'.$nl);
12+
}

0 commit comments

Comments
 (0)