Permalink
Browse files

Add support for travis-ci.org

  • Loading branch information...
1 parent 1a34a8a commit 30edcdb47884ab4f14bd498b2f2b32c5314f1402 Drak committed Nov 28, 2011
Showing with 44 additions and 151 deletions.
  1. +12 −0 .travis.yml
  2. +19 −0 phpunit.xml.dist
  3. +9 −151 tests/lib/Tests/Zikula/ServiceManagerTest.php
  4. +4 −0 vendors.php
View
12 .travis.yml
@@ -0,0 +1,12 @@
+language: php
+
+php:
+ - 5.3
+ - 5.4
+
+before_install:
+ - pyrus install --alldeps pear/PHP_CodeSniffer
+ - pyrus install --alldeps phpunit/PHP_CodeCoverage
+ - phpenv rehash
+
+before_script: php vendors.php
View
19 phpunit.xml.dist
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<phpunit backupGlobals="false"
+ backupStaticAttributes="false"
+ colors="true"
+ convertErrorsToExceptions="true"
+ convertNoticesToExceptions="true"
+ convertWarningsToExceptions="true"
+ processIsolation="false"
+ stopOnFailure="false"
+ syntaxCheck="false"
+ bootstrap="tests/bootstrap.php"
+>
+ <testsuites>
+ <testsuite name="Zikula Test Suite">
+ <directory>./tests/lib/Tests/</directory>
+ </testsuite>
+ </testsuites>
+</phpunit>
View
160 tests/lib/Tests/Zikula/ServiceManagerTest.php
@@ -59,9 +59,6 @@ protected function setUp()
{
parent::setUp();
$this->serviceManager = new Zikula_ServiceManager();
- $property = new ReflectionProperty($this->serviceManager, 'services');
- $property->setAccessible(true);
- $this->services = $property->setValue($this->serviceManager, array());//$property->getValue($this->ServiceManager);
}
/**
@@ -109,9 +106,8 @@ public function testDetachService()
$this->serviceManager->attachService('test.stdclass1', $class1);
$this->serviceManager->attachService('test.stdclass2', $class2);
$this->serviceManager->detachService('test.stdclass1');
- $expected = new Zikula_ServiceManager_Service('test.stdclass2', null);
- $expected->setService($class2);
- $this->assertAttributeEquals(array('test.stdclass2' => $expected), 'services', $this->serviceManager);
+ $this->assertFalse($this->serviceManager->hasService('test.stdclass1'));
+ $this->assertTrue($this->serviceManager->hasService('test.stdclass2'));
}
/**
@@ -182,152 +178,12 @@ public function testHasService()
$this->assertTrue($this->serviceManager->hasService('will.pass'));
}
- /**
- * Tests ServiceManager->createService()
- * @dataProvider providerCreateService
- */
- public function testCreateService($test, $input, $expectedOutput)
- {
- // unprotected the createService() method.
- $method = new ReflectionMethod('Zikula_ServiceManager', 'createService');
- $method->setAccessible(true);
- $this->$test($expectedOutput, $method->invokeArgs($this->serviceManager, array($input)));
- }
-
- public function providerCreateService()
- {
- $store = new Store('store');
- $store2 = new Store('store2');
-
- $inner = new Store(new StdClass);
- $inner->setFoo(new ArrayObject);
- $nestedStore = new Store(new Store($inner));
-
- return array(
- array('assertEquals', new Zikula_ServiceManager_Definition('StdClass', array(), array()), new StdClass()),
- array('assertEquals', new Zikula_ServiceManager_Definition('ArrayObject', array(), array()), new ArrayObject()),
- array('assertEquals', new Zikula_ServiceManager_Definition('EmptyIterator', array(), array()), new EmptyIterator()),
-
- // nasty recursive test on definitions.
- array('assertEquals', new Zikula_ServiceManager_Definition('Store', array(new Zikula_ServiceManager_Definition('Store', array(new Zikula_ServiceManager_Definition('Store', array(new Zikula_ServiceManager_Definition('StdClass'))))))), new Store(new Store(new Store(new StdClass)))),
-
- // test parameterless method call.
- array('assertEquals', new Zikula_ServiceManager_Definition('Store', array('store'), array('touchFlag' => array())), $store->touchFlag()),
-
- // test method call with param.
- array('assertEquals', new Zikula_ServiceManager_Definition('Store', array('ok'), array('setData' => array('ok'))), new Store('ok')),
-
- // test multiple method calls.
- array('assertEquals', new Zikula_ServiceManager_Definition('Store', array('store2'), array('touchFlag' => array(), 'setFoo' => array('bar'))), $store2->setFoo('bar')->touchFlag()),
-
- // test method call with Definition as method param.
- array('assertEquals', new Zikula_ServiceManager_Definition('Store', array('ok'), array('setData' => array(new Zikula_ServiceManager_Definition('\ArrayObject')))), new Store(new ArrayObject())),
-
- // nasty recursive test on definitions with Definition as method param.
- array('assertEquals', new Zikula_ServiceManager_Definition('Store', array(new Zikula_ServiceManager_Definition('Store', array(new Zikula_ServiceManager_Definition('Store', array(new Zikula_ServiceManager_Definition('StdClass')), array('setFoo' => array(new Zikula_ServiceManager_Definition('ArrayObject')))))))), new Store(new Store($inner))),
- );
- }
-
- /**
- * Tests ServiceManager->createService()
- * Test createServices with Service containers in method params.
- * @dataProvider providerCreateServiceService
- */
- public function testCreateServiceService($test, $input, $expectedOutput, $service, $id)
- {
- // setup expected service
- $this->serviceManager->attachService($id, $service);
-
- // unprotected the createService() method.
- $method = new ReflectionMethod('Zikula_ServiceManager', 'createService');
- $method->setAccessible(true);
- $this->$test($expectedOutput, $method->invokeArgs($this->serviceManager, array($input)));
- }
-
- public function providerCreateServiceService()
- {
- $store1 = new Store('store1');
- $store2 = new ArrayObject();
-
- $inner = new Store(new StdClass);
- $inner->setFoo($store2);
- $nestedStore = new Store(new Store($inner));
-
- return array(
- // test method call with Service reference in method param.
- array('assertEquals', new Zikula_ServiceManager_Definition('Store', array('ok'), array('setData' => array(new Zikula_ServiceManager_Service('store1')))), new Store($store1), $store1, 'store1'),
-
- // nasty recursive test on definitions with Service as method param.
- array('assertEquals', new Zikula_ServiceManager_Definition('Store', array(new Zikula_ServiceManager_Definition('Store', array(new Zikula_ServiceManager_Definition('Store', array(new Zikula_ServiceManager_Definition('StdClass')), array('setFoo' => array(new Zikula_ServiceManager_Service('store2')))))))), new Store(new Store($inner)), $store2, 'store2'),
- );
- }
-
- /**
- * Tests ServiceManager->compileArguments()
- * @dataProvider providerCompileArguments
- */
- public function testCompileArguments($test, $input, $expectedOutput, $services)
- {
- // unprotected the compileArgs() method.
- $method = new ReflectionMethod('Zikula_ServiceManager', 'compileArguments');
- $method->setAccessible(true);
-
- if (is_array($services)) {
- foreach ($services as $k => $v) {
- $this->serviceManager->attachService($k, $v);
- }
- }
-
- $this->$test($expectedOutput, $method->invokeArgs($this->serviceManager, array($input)));
- }
-
- public function providerCompileArguments()
- {
- // definition classes
- $def1 = new Zikula_ServiceManager_Definition('StdClass');
- $def2 = new Zikula_ServiceManager_Definition('ArrayObject');
- $def3 = new Zikula_ServiceManager_Definition('EmptyIterator');
-
- // created services
- $std1 = new StdClass();
- $std2 = new ArrayObject();
- $std3 = new EmptyIterator();
-
- // service references
- $srv1 = new Zikula_ServiceManager_Reference('test.1');
- $srv2 = new Zikula_ServiceManager_Reference('test.2');
- $srv3 = new Zikula_ServiceManager_Reference('test.3');
-
- // service arguments
- $arg1 = new Zikula_ServiceManager_Argument('arg.1');
- $arg2 = new Zikula_ServiceManager_Argument('arg.2');
- $arg3 = new Zikula_ServiceManager_Argument('arg.3');
-
- // plain variables
- $var1 = 'string';
- $var2 = 123;
- $var3 = true;
-
- return array(
- array('assertSame', array(1,2,3,4,5), array(1,2,3,4,5), null),
- array('assertNotSame', array(1,2,3,4,5), array(1,2,3), null),
- array('assertEquals', array('a', 'b', $def1), array('a', 'b', $std1), null),
- array('assertEquals', array($def1, 'b', $def2), array($std1, 'b', $std2), null),
- array('assertNotEquals', array('a', 'b', $def1), array('a', 'b', 'c'), null),
- array('assertEquals', array($def1, $def2, $def3), array($std1, $std2, $std3), null),
- array('assertEquals', array($def1, $def2, $def3), array($std1, $std2, $std3), null),
- array('assertNotSame', array($srv1, $srv2, $srv3), array($std1, $std1, $std1), array('test.1' => $std1,'test.2' => $std2,'test.3' => $std3)),
- array('assertSame', array($srv1, $srv2, $srv3), array($std1, $std2, $std3), array('test.1' => $std1,'test.2' => $std2,'test.3' => $std3)),
- array('assertSame', array($srv1, $srv2, 1), array($std1, $std2, 1), array('test.1' => $std1,'test.2' => $std2)),
- );
- }
-
- public function testregisterService()
+ public function testRegisterService()
{
$definition = new Zikula_ServiceManager_Definition('StdClass');
$service = new Zikula_ServiceManager_Service('test.service', $definition);
$this->serviceManager->registerService('test.service', $definition);
- $this->assertAttributeSame(array('test.service' => $service), 'services', $this->serviceManager);
+ $this->assertTrue($this->serviceManager->getService('test.service') instanceof StdClass);
}
public function testRegisterServiceExceptionAlreadyRegistered()
@@ -341,19 +197,21 @@ public function testRegisterServiceExceptionAlreadyRegistered()
public function testRegisterServiceExceptionNoDefinition()
{
- $this->setExpectedException('Exception');
+ $this->setExpectedException('InvalidArgumentException');
+ $this->serviceManager->registerService('test.service');
$this->serviceManager->registerService('test.service');
}
- public function testunregisterService()
+ public function testUnregisterService()
{
$definition = new Zikula_ServiceManager_Definition('StdClass');
$service1 = new Zikula_ServiceManager_Service('test.service1', $definition);
$service2 = new Zikula_ServiceManager_Service('test.service2', $definition);
$this->serviceManager->registerService('test.service1', $definition);
$this->serviceManager->registerService('test.service2', $definition);
$this->serviceManager->unregisterService('test.service1');
- $this->assertAttributeSame(array('test.service2' => $service2), 'services', $this->serviceManager);
+ $this->assertTrue($this->serviceManager->hasService('test.service2'));
+ $this->assertFalse($this->serviceManager->hasService('test.service1'));
}
public function testUnregisterServiceException()
View
4 vendors.php
@@ -0,0 +1,4 @@
+#!/usr/bin/env php
+<?php
+set_time_limit(0);
+

0 comments on commit 30edcdb

Please sign in to comment.