コード例 #1
0
 public function testAddDependency()
 {
     $for = 'foo';
     $className = 'className';
     $dependency = new Dependency($className);
     $container = new DependencyContainer();
     $container->addDependency($for, $dependency);
     $expected = array($for => array(0 => $dependency));
     $this->assertEquals($expected, Reflection::getProperty($container, 'dependencies'));
     $this->assertEquals(0, $dependency->getId());
     $id = 'id';
     $dependency->setId($id);
     $container->addDependency($for, $dependency);
     $expected[$for][$id] = $dependency;
     $this->assertEquals($expected, Reflection::getProperty($container, 'dependencies'));
     $for = "bar";
     $container->addDependency($for, $dependency);
     $expected[$for][$id] = $dependency;
     $this->assertEquals($expected, Reflection::getProperty($container, 'dependencies'));
     $for = "foo";
     $dependency->setId();
     $container->addDependency($for, $dependency);
     $expected[$for][1] = $dependency;
     $this->assertEquals($expected, Reflection::getProperty($container, 'dependencies'));
     $this->assertEquals(1, $dependency->getId());
 }
コード例 #2
0
ファイル: ZiboTest.php プロジェクト: BGCX261/zibo-svn-to-git
 protected function tearDown()
 {
     try {
         Reflection::setProperty(Zibo::getInstance(), 'instance', null);
     } catch (ZiboException $e) {
     }
 }
コード例 #3
0
 /**
  * @dataProvider providerConstruct
  */
 public function testConstruct($expectedId, $url)
 {
     $youtube = new Youtube($url);
     $this->assertEquals(Youtube::DEFAULT_HEIGHT, Reflection::getProperty($youtube, 'height'));
     $this->assertEquals(Youtube::DEFAULT_WIDTH, Reflection::getProperty($youtube, 'width'));
     $this->assertEquals($expectedId, $youtube->getVideoId());
 }
コード例 #4
0
 public function testConstruct()
 {
     $cache = $this->getMockForAbstractClass('zibo\\library\\cache\\AbstractCache');
     $io = Reflection::getProperty($cache, 'io');
     $this->assertNotNull($io);
     $this->assertTrue($io instanceof CacheIO);
 }
コード例 #5
0
 /**
  * @dataProvider providerGetLocalesSortsLocales
  */
 public function testSetOrderSortsLocales($order, $codeA, $codeB = null, $codeC = null, $codeD = null)
 {
     $this->manager->setOrder($order);
     $locales = Reflection::getProperty($this->manager, 'locales');
     $this->assertEquals(4, count($locales));
     $i = 0;
     foreach ($locales as $key => $locale) {
         switch ($i) {
             case 0:
                 $this->assertEquals($codeA, $key);
                 $this->assertEquals($codeA, $locale->getCode());
                 break;
             case 1:
                 if ($codeB) {
                     $this->assertEquals($codeB, $key);
                     $this->assertEquals($codeB, $locale->getCode());
                 }
                 break;
             case 2:
                 if ($codeC) {
                     $this->assertEquals($codeC, $key);
                     $this->assertEquals($codeC, $locale->getCode());
                 }
                 break;
             case 3:
                 if ($codeD) {
                     $this->assertEquals($codeD, $key);
                     $this->assertEquals($codeD, $locale->getCode());
                 }
                 break;
         }
         $i++;
     }
 }
コード例 #6
0
 public function testConstructWithRegex()
 {
     $regex = 'regex';
     $validator = new RegexValidator(array('regex' => $regex));
     $validatorRegex = Reflection::getProperty($validator, 'regex');
     $this->assertEquals($regex, $validatorRegex);
 }
コード例 #7
0
 public function testRegister()
 {
     $this->createEmptyThumbnailerMock();
     $this->factory->register($this->mockName, $this->mockThumbnailer);
     $thumbnailers = Reflection::getProperty($this->factory, 'thumbnailers');
     $this->assertArrayHasKey($this->mockName, $thumbnailers);
     $this->assertEquals($this->mockThumbnailer, $thumbnailers[$this->mockName]);
 }
コード例 #8
0
 public function testConstruct()
 {
     $name = 'name';
     $format = 'format';
     $dataFormat = new DataFormat($name, $format);
     $this->assertEquals($name, Reflection::getProperty($dataFormat, 'name'));
     $this->assertEquals($format, Reflection::getProperty($dataFormat, 'format'));
 }
コード例 #9
0
 public function testSetAllowedNames()
 {
     $name = 'name';
     $name2 = 'name2';
     $expected = array($name, $name2);
     $this->filter->setAllowedNames($expected);
     $this->assertEquals($expected, Reflection::getProperty($this->filter, 'names'));
 }
コード例 #10
0
 public function testConstruct()
 {
     $name = 'name';
     $options = array('option' => 'value');
     $fieldValidator = new FieldValidator($name, $options);
     $this->assertEquals($name, Reflection::getProperty($fieldValidator, 'name'));
     $this->assertEquals($options, Reflection::getProperty($fieldValidator, 'options'));
 }
コード例 #11
0
ファイル: IndexTest.php プロジェクト: BGCX261/zibo-svn-to-git
 public function testConstruct()
 {
     $name = 'index';
     $fields = array('id' => new Field('id', 'integer'), 'name' => new Field('name', 'string'));
     $index = new Index($name, $fields);
     $this->assertEquals($name, Reflection::getProperty($index, 'name'));
     $this->assertEquals($fields, Reflection::getProperty($index, 'fields'));
 }
コード例 #12
0
 public function testRegister()
 {
     $this->createEmptyIOMock();
     $this->factory->register($this->mockExtension, $this->mockIO);
     $io = Reflection::getProperty($this->factory, 'io');
     $this->assertArrayHasKey($this->mockExtension, $io);
     $this->assertEquals($this->mockIO, $io[$this->mockExtension]);
 }
コード例 #13
0
 public function tearDown()
 {
     Reflection::setProperty(Zibo::getInstance(), 'instance', null);
     if (file_exists('application/config/modules.temp.xml')) {
         unlink('application/config/modules.temp.xml');
     }
     $this->tearDownApplication();
 }
コード例 #14
0
 public function testAddErrors()
 {
     $name = 'field';
     $errors = array(new ValidationError('code1', 'message1'), new ValidationError('code2', 'message2'));
     $this->exception->addErrors($name, $errors);
     $exceptionErrors = Reflection::getProperty($this->exception, 'errors');
     $this->assertEquals(array($name => $errors), $exceptionErrors);
 }
コード例 #15
0
 /**
  * @dataProvider providerGetParent
  */
 public function testGetParent($expected, $value)
 {
     $currentFileSystem = FileSystem::getInstance();
     $windowsFileSystem = new WindowsFileSystem();
     Reflection::setProperty(FileSystem::getInstance(), 'instance', $windowsFileSystem);
     $file = new File($value);
     $this->assertEquals(new File($expected), $windowsFileSystem->getParent($file));
     Reflection::setProperty(FileSystem::getInstance(), 'instance', $currentFileSystem);
 }
コード例 #16
0
 public function testRegisterFilter()
 {
     $filterName = 'trim';
     $filterClass = 'zibo\\library\\validation\\filter\\TrimFilter';
     $this->factory->registerFilter($filterName, $filterClass);
     $filters = Reflection::getProperty($this->factory, 'filters');
     $this->assertArrayHasKey($filterName, $filters);
     $this->assertContains($filterClass, $filters);
 }
コード例 #17
0
 public function testSetDateFormat()
 {
     $identifier = 'id';
     $format = 'd-m-Y';
     $locale = new Locale('en', 'en');
     $locale->setDateFormat($identifier, $format);
     $expected = array($identifier => $format);
     $this->assertEquals($expected, Reflection::getProperty($locale, 'dateFormats'));
 }
コード例 #18
0
 public function testGetInstanceLoadsCaptchas()
 {
     $config = array('mock' => self::CAPTCHA_MOCK);
     $this->configIOMock->setValues('captcha', $config);
     $manager = CaptchaManager::getInstance();
     $captchas = Reflection::getProperty($manager, 'captchas');
     $this->assertTrue(is_array($captchas));
     $this->assertTrue(array_key_exists('mock', $captchas));
 }
コード例 #19
0
 public function testConnect()
 {
     $connection = new Connection($this->host);
     $this->assertNull(Reflection::getProperty($connection, 'socket'));
     $connection->connect();
     $this->assertNotNull(Reflection::getProperty($connection, 'socket'));
     $connection->disconnect();
     $this->assertNull(Reflection::getProperty($connection, 'socket'));
 }
コード例 #20
0
 public function testExecute()
 {
     $browser = new GenericBrowser(new File(getcwd()));
     $this->configIOMock = new ConfigIOMock();
     $zibo = Zibo::getInstance($browser, $this->configIOMock);
     $string = 'This is a test string.' . "\n\n" . 'We would like to have multiple lines.';
     $output = System::execute('echo \'' . $string . '\'');
     $this->assertEquals($string, $output);
     Reflection::setProperty(Zibo::getInstance(), 'instance', null);
 }
コード例 #21
0
 public function testConstructWithMinimumAndMaximum()
 {
     $minimum = 4;
     $maximum = 8;
     $validator = new SizeValidator(array('minimum' => $minimum, 'maximum' => $maximum));
     $validatorMinimum = Reflection::getProperty($validator, 'minimum');
     $validatorMaximum = Reflection::getProperty($validator, 'maximum');
     $this->assertEquals($minimum, $validatorMinimum);
     $this->assertEquals($maximum, $validatorMaximum);
 }
コード例 #22
0
 public function testConstruct()
 {
     $client = new Client('http://time.xmlrpc.com:80/RPC2');
     $host = Reflection::getProperty($client, 'host');
     $this->assertEquals('time.xmlrpc.com', $host, 'host is not the expected host');
     $port = Reflection::getProperty($client, 'port');
     $this->assertEquals(80, $port, 'port is not the expected port');
     $path = Reflection::getProperty($client, 'path');
     $this->assertEquals('/RPC2', $path, 'path is not the expected path');
 }
コード例 #23
0
 public function testSetEmoticonImage()
 {
     $emoticonParser = new EmoticonParser($this->emoticons);
     $emoticon = ':-(';
     $image = 'web/images/sad.png';
     $this->emoticons[$emoticon] = $image;
     $emoticonParser->setEmoticonImage($emoticon, $image);
     $parserEmoticons = Reflection::getProperty($emoticonParser, 'emoticons');
     $this->assertEquals($this->emoticons, $parserEmoticons);
 }
コード例 #24
0
 public function testRegisterServiceWithoutParameters()
 {
     $expected = array('callback' => new Callback($this->callback), 'return' => $this->resultType, 'parameters' => array(), 'description' => null);
     $this->server->registerService($this->serviceName, $this->callback, $this->resultType);
     $services = Reflection::getProperty($this->server, 'services');
     $this->assertNotNull($services, 'services is null');
     $this->assertTrue(is_array($services), 'services is no array');
     $this->assertEquals(1, count($services), 'services has unexpected count');
     $this->assertTrue(isset($services[$this->serviceName]), 'registered service is not set');
     $this->assertEquals($expected, $services[$this->serviceName]);
 }
コード例 #25
0
 /**
  * @dataProvider providerIsValid
  */
 public function testIsValid($expected, $test)
 {
     $validator = new DsnValidator();
     $result = $validator->isValid($test);
     $this->assertEquals($expected, $result);
     if (!$expected) {
         $resultErrors = $validator->getErrors();
         $regex = Reflection::getProperty($validator, 'regex');
         $expectedParameters = array('value' => $test, 'regex' => $regex);
         $expectedErrors = array(new ValidationError(DsnValidator::CODE, DsnValidator::MESSAGE, $expectedParameters));
         $this->assertEquals($expectedErrors, $resultErrors);
     }
 }
コード例 #26
0
 /**
  * @dataProvider providerIsValid
  */
 public function testIsValid($expected, $value)
 {
     $validator = new WebsiteValidator();
     $result = $validator->isValid($value);
     $this->assertEquals($expected, $result, $value);
     if (!$expected) {
         $regex = Reflection::getProperty($validator, 'regex');
         $expectedParameters = array('value' => $value, 'regex' => $regex);
         $expectedError = new ValidationError(WebsiteValidator::CODE, WebsiteValidator::MESSAGE, $expectedParameters);
         $resultErrors = $validator->getErrors();
         $this->assertEquals(array($expectedError), $resultErrors);
     }
 }
コード例 #27
0
 public function testRegisterModel()
 {
     $field = new PropertyField('field', 'type');
     $model = $this->createModel('table', array($field));
     $model2 = $this->createModel('table2', array($field));
     $this->register->registerModel($model);
     $this->register->registerModel($model2);
     $models = Reflection::getProperty($this->register, 'models');
     $this->assertTrue(is_array($models), 'models is not an array');
     $this->assertTrue(isset($models[$model2->getName()]), $model2->getName() . ' is not set');
     $this->assertEquals($model2, $models[$model2->getName()]);
     $this->assertTrue(isset($models[$model->getName()]), $model->getName() . ' is not set');
     $this->assertEquals($model, $models[$model->getName()]);
 }
コード例 #28
0
 public function testGetArchive()
 {
     if (!class_exists('ZipArchive')) {
         $this->markTestSkipped('Zip is unsupported on this system.');
     }
     $typeName = 'zip';
     $typeClass = 'zibo\\library\\archive\\Zip';
     $factory = ArchiveFactory::getInstance();
     $factory->register($typeName, $typeClass);
     $file = new File('test.zip');
     $archive = $factory->getArchive($file);
     $archiveFile = Reflection::getProperty($archive, 'file');
     $this->assertEquals($file, $archiveFile);
 }
コード例 #29
0
 /**
  * @dataProvider providerConstruct
  */
 public function testConstruct($minimum, $maximum)
 {
     $options = array();
     if ($minimum !== null) {
         $options[MinMaxValidator::OPTION_MINIMUM] = $minimum;
     }
     if ($maximum !== null) {
         $options[MinMaxValidator::OPTION_MAXIMUM] = $maximum;
     }
     $validator = new MinMaxValidator($options);
     $validatorMinimum = Reflection::getProperty($validator, 'minimum');
     $validatorMaximum = Reflection::getProperty($validator, 'maximum');
     $this->assertEquals($minimum, $validatorMinimum);
     $this->assertEquals($maximum, $validatorMaximum);
 }
コード例 #30
0
 protected function getConnection($connect = true)
 {
     $dsn = Zibo::getInstance()->getConfigValue('database.connection.mysql');
     if ($dsn == null) {
         Reflection::setProperty(Zibo::getInstance(), 'instance', null);
         $this->markTestSkipped('No dsn found for database.connection.mysql, check config/database.ini');
         return;
     }
     $this->dsn = new Dsn($dsn);
     $connection = new MysqlDriver($this->dsn);
     if ($connect) {
         $connection->connect();
     }
     return $connection;
 }