/** * Magic function which handles the properties accessibility. * @param string $propertyName The property name. */ public function __get($propertyName) { switch ($propertyName) { case '_baseExtendableObject': return $this->_baseExtendableObject; default: $class = new \ReflectionClass($this); if ($class->hasProperty($propertyName)) { $property = $class->getProperty($propertyName); $property->setAccessible(true); return $property->getValue($this); } else { if ($class->hasProperty('_' . $propertyName)) { $property = $class->getProperty('_' . $propertyName); $property->setAccessible(true); return $property->getValue($this); } else { $baseClass = new \ReflectionClass($_baseExtendableObject); $method = $baseClass->getMethod('__get'); return $method->invoke($this, $propertyName); } } return null; } }
public function testAddExternalField() { $this->assertClassHasStaticAttribute('_fieldTable', '\\Test\\ItemExt'); $this->assertClassHasStaticAttribute('_tableForeignKeys', '\\Test\\ItemExt'); $itemExtReflection = new \ReflectionClass('\\Test\\ItemExt'); $fieldsReflection = $itemExtReflection->getProperty('_fieldTable'); $fieldsReflection->setAccessible(true); $this->assertTrue(is_array($fieldsReflection->getValue())); $this->assertCount(0, $fieldsReflection->getValue()); $tablesReflection = $itemExtReflection->getProperty('_tableForeignKeys'); $tablesReflection->setAccessible(true); $this->assertTrue(is_array($tablesReflection->getValue())); $this->assertCount(0, $tablesReflection->getValue()); ItemExt::init(); $this->assertCount(6, $fieldsReflection->getValue()); $this->assertTrue(isset($fieldsReflection->getValue()['city_name'])); $this->assertTrue(isset($fieldsReflection->getValue()['city_population'])); $this->assertTrue(isset($fieldsReflection->getValue()['sku'])); $this->assertTrue(isset($fieldsReflection->getValue()['length'])); $this->assertTrue(isset($fieldsReflection->getValue()['width'])); $this->assertTrue(isset($fieldsReflection->getValue()['height'])); $this->assertCount(2, $tablesReflection->getValue()); $this->assertTrue(isset($tablesReflection->getValue()['item_city'])); $this->assertTrue(isset($tablesReflection->getValue()['item_properties'])); }
/** * @covers ::__construct * @covers ::getMethod * @covers ::getPath * @covers ::getAcceptHeader * @covers ::getAuthorizationHeader * @covers ::getCookie * @covers ::getPost */ public function testConstruct() { $cookie = new Cookie($this->configuration); $server = ['HTTPS' => 'https', 'HTTP_HOST' => 'www.example.com', 'HTTP_ACCEPT' => 'application/json', 'HTTP_AUTHORIZATION' => 'foo', 'REQUEST_URI' => '/']; $post = ['User.Email' => '*****@*****.**']; $request = new Request($cookie, $server, $post); $reflector = new \ReflectionClass($request); $methodProperty = $reflector->getProperty('method'); $methodProperty->setAccessible(true); $this->assertSame('GET', $methodProperty->getValue($request)); $this->assertSame('GET', $request->getMethod()); $urlProperty = $reflector->getProperty('url'); $urlProperty->setAccessible(true); $this->assertSame('https://www.example.com', $urlProperty->getValue($request)); $this->assertSame('', $request->getPath()); $expectedHeaders = ['Accept' => 'application/json', 'Authorization' => 'foo']; $headersProperty = $reflector->getProperty('headers'); $headersProperty->setAccessible(true); $this->assertSame($expectedHeaders, $headersProperty->getValue($request)); $this->assertSame('application/json', $request->getAcceptHeader()); $this->assertSame('foo', $request->getAuthorizationHeader()); $cookieProperty = $reflector->getProperty('cookie'); $cookieProperty->setAccessible(true); $this->assertSame($cookie, $cookieProperty->getValue($request)); $this->assertSame($cookie, $request->getCookie()); $postProperty = $reflector->getProperty('post'); $postProperty->setAccessible(true); $this->assertSame($post, $postProperty->getValue($request)); $this->assertSame($post, $request->getPost()); }
/** * @dataProvider getThumbnailSourceProvider * @covers File::getThumbnailSource */ public function testGetThumbnailSource($data) { $backendMock = $this->getMockBuilder('FSFileBackend')->setConstructorArgs([['name' => 'backendMock', 'wikiId' => wfWikiID()]])->getMock(); $repoMock = $this->getMockBuilder('FileRepo')->setConstructorArgs([['name' => 'repoMock', 'backend' => $backendMock]])->setMethods(['fileExists', 'getLocalReference'])->getMock(); $fsFile = new FSFile('fsFilePath'); $repoMock->expects($this->any())->method('fileExists')->will($this->returnValue(true)); $repoMock->expects($this->any())->method('getLocalReference')->will($this->returnValue($fsFile)); $handlerMock = $this->getMock('BitmapHandler', ['supportsBucketing']); $handlerMock->expects($this->any())->method('supportsBucketing')->will($this->returnValue($data['supportsBucketing'])); $fileMock = $this->getMockBuilder('File')->setConstructorArgs(['fileMock', $repoMock])->setMethods(['getThumbnailBucket', 'getLocalRefPath', 'getHandler'])->getMockForAbstractClass(); $fileMock->expects($this->any())->method('getThumbnailBucket')->will($this->returnValue($data['thumbnailBucket'])); $fileMock->expects($this->any())->method('getLocalRefPath')->will($this->returnValue('localRefPath')); $fileMock->expects($this->any())->method('getHandler')->will($this->returnValue($handlerMock)); $reflection = new ReflectionClass($fileMock); $reflection_property = $reflection->getProperty('handler'); $reflection_property->setAccessible(true); $reflection_property->setValue($fileMock, $handlerMock); if (!is_null($data['tmpBucketedThumbCache'])) { $reflection_property = $reflection->getProperty('tmpBucketedThumbCache'); $reflection_property->setAccessible(true); $reflection_property->setValue($fileMock, $data['tmpBucketedThumbCache']); } $result = $fileMock->getThumbnailSource(['physicalWidth' => $data['physicalWidth']]); $this->assertEquals($data['expectedPath'], $result['path'], $data['message']); }
/** * You cannot create an instance of Schema class * directly * * @param $model */ protected function __construct($model) { $this->klass = $model; if (class_exists(get_class($this->klass))) { $reflectionClass = new \ReflectionClass(get_class($this->klass)); /* | We will set the database connection name here */ if (property_exists($this->klass, 'database')) { $reflectionProperty = $reflectionClass->getProperty('database'); $reflectionProperty->setAccessible(true); $this->database = $reflectionProperty->getValue($this->klass); } else { $this->database = $this->getDefaultConnection(); } /* | We will set the primary key of the table schema */ if (property_exists($this->klass, 'primaryKey')) { $reflectionPropertyKey = $reflectionClass->getProperty('primaryKey'); $reflectionPropertyKey->setAccessible(true); $this->primaryKey = $reflectionPropertyKey->getValue($this->klass); } /* | Set database connection name */ $this->setDatabaseConnection($this->database); if (!property_exists($this->klass, 'tableName')) { $this->tableName = Inflector::tabilize(get_class($this->klass)); } } }
/** * Testing annotations. * * @test */ public function testAnnotations() { $sut = new AsDateTime(); $reflection = new \ReflectionClass($sut); $comments = $reflection->getDocComment(); $expected = preg_quote('@Annotation'); $results = preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches); $this->assertEquals(1, $results); $expected = preg_quote('@Target({"PROPERTY"})'); $this->assertEquals(1, preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches)); $property = $reflection->getProperty('allowNull'); $comments = $property->getDocComment(); $expected = preg_quote('@var ') . '(bool|boolean)'; $this->assertEquals(1, preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches)); // $property = $reflection->getProperty('min'); $comments = $property->getDocComment(); $expected = preg_quote('@var \\DateTime'); $this->assertEquals(1, preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches)); $property = $reflection->getProperty('max'); // $comments = $property->getDocComment(); $expected = preg_quote('@var \\DateTime'); $this->assertEquals(1, preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches)); }
/** * @test * @group library */ public function successfullyDecompressGzRawPostData() { $compressedRequestFileDirectory = Registry::getConfig()->test->request->storage->directory . DIRECTORY_SEPARATOR . 'compressed' . DIRECTORY_SEPARATOR; $compressedRawBodyFile = $compressedRequestFileDirectory . 'gzCompressed.body'; $decompressedParamFile = $compressedRequestFileDirectory . 'gzDeompressedParams.php'; $this->assertFileExists($compressedRawBodyFile, 'Komprimierte Test-Request-Datei nicht gefunden: ' . $compressedRawBodyFile); $this->assertFileExists($decompressedParamFile, 'Dekomprimierte Test-Param-Variablen-Datei nicht gefunden: ' . $decompressedParamFile); // Dekomprimierte Werte ermitteln $decompressedParams = (include $decompressedParamFile); // Request-Objekt erzeugen $request = new HttpRequestCompressed(); // Raw Post Daten setzen $_SERVER['REQUEST_METHOD'] = 'POST'; $_SERVER['HTTP_X_CMS_ENCODING'] = 'gz'; $reflectionClass = new \ReflectionClass('Cms\\Controller\\Request\\HttpCompressed'); $reflectionPropertyDecompressedFlag = $reflectionClass->getProperty('postDataDecompressed'); $reflectionPropertyDecompressedFlag->setAccessible(true); $reflectionPropertyDecompressedFlag->setValue($request, false); $reflectionPropertyRawBody = $reflectionClass->getProperty('_rawBody'); $reflectionPropertyRawBody->setAccessible(true); $reflectionPropertyRawBody->setValue($request, file_get_contents($compressedRawBodyFile)); // Dekomprimieren $request->decompressRequest(); // Dekomprimierung pruefen $jsonParams = $request->getParam(\Cms\Request\Base::REQUEST_PARAMETER); $this->assertInternalType('string', $jsonParams); $params = json_decode($jsonParams, true); $this->assertInternalType('array', $params); $this->assertSame($decompressedParams, $params); }
/** * */ public function testGetSiteMapCollection() { $this->assertInstanceOf('Evheniy\\SitemapXmlBundle\\Collection\\SiteMapCollection', $this->siteMapIndexEntity->getSiteMapCollection()); $siteMapCollection = $this->reflectionClass->getProperty('siteMapCollection'); $siteMapCollection->setAccessible(true); $this->assertEquals($siteMapCollection->getValue($this->siteMapIndexEntity), $this->siteMapIndexEntity->getSiteMapCollection()); }
public function setUp() { parent::setUp(); $this->date = $date = date('YmdHi'); $this->mock = $this->getMockBuilder('NodExportController')->disableOriginalConstructor()->getMock(); $this->mock->method('createAllTempTables'); $reflectionClass = new ReflectionClass('NodExportController'); $institutionCode = $reflectionClass->getProperty('institutionCode'); $institutionCode->setAccessible(true); $institutionCode->setValue($this->mock, Yii::app()->params['institution_code']); $exportPath = $reflectionClass->getProperty('exportPath'); $exportPath->setAccessible(true); $exportPath->setValue($this->mock, realpath(dirname(__FILE__) . '/../../../') . '/runtime/nod-export/test/' . $institutionCode->getValue($this->mock) . '/' . $this->date); $zipName = $reflectionClass->getProperty('zipName'); $zipName->setAccessible(true); $zipName->setValue($this->mock, $institutionCode->getValue($this->mock) . '_' . $this->date . '_NOD_Export.zip'); $this->controller = $reflectionClass; $this->exportPath = $exportPath->getValue($this->mock); $this->zipName = $zipName->getValue($this->mock); if (!file_exists($exportPath->getValue($this->mock))) { mkdir($exportPath->getValue($this->mock), 0777, true); } $createAllTempTablesmethod = $this->controller->getMethod('createAllTempTables'); $createAllTempTablesmethod->setAccessible(true); $createAllTempTablesmethod->invoke($this->mock); }
/** * @test */ public function test_parse_property_annotation() { $intf = new \ReflectionClass(Todo::class); $commentParser = new AnnotationConverterAdapter($intf); id: $annotations = $commentParser->getPropertyAnnotations($intf->getProperty('id')); $this->assertCount(2, $annotations); $this->assertInstanceOf(Column::class, $annotations[0]); $this->assertEquals('todo_id', $annotations[0]->name); $this->assertNull($annotations[0]->default); $this->assertCount(0, $annotations[0]->optFields); $this->assertInstanceOf(ColumnType::class, $annotations[1]); $this->assertEquals('integer', $annotations[1]->type); $this->assertEquals('id', $annotations[1]->name); todo: $annotations = $commentParser->getPropertyAnnotations($intf->getProperty('todo')); $this->assertCount(3, $annotations); $this->assertInstanceOf(Column::class, $annotations[0]); $this->assertEquals('content', $annotations[0]->name); $this->assertNull($annotations[0]->default); $this->assertCount(0, $annotations[0]->optFields); $this->assertInstanceOf(Alias::class, $annotations[1]); $this->assertEquals('content', $annotations[1]->name); $this->assertEquals(['text', 'memo'], $annotations[1]->alias); $this->assertInstanceOf(ColumnType::class, $annotations[2]); $this->assertEquals('string', $annotations[2]->type); $this->assertEquals('todo', $annotations[2]->name); created: $annotations = $commentParser->getPropertyAnnotations($intf->getProperty('created')); $this->assertCount(1, $annotations); $this->assertInstanceOf(ColumnType::class, $annotations[0]); $this->assertEquals(\DateTime::class, $annotations[0]->type); $this->assertEquals('created', $annotations[0]->name); hidden: $annotations = $commentParser->getPropertyAnnotations($intf->getProperty('hidden')); $this->assertCount(2, $annotations); $this->assertInstanceOf(Column::class, $annotations[0]); $this->assertNull(null, $annotations[0]->name); $this->assertEquals(0, $annotations[0]->default); $this->assertCount(0, $annotations[0]->optFields); $this->assertInstanceOf(ColumnType::class, $annotations[1]); $this->assertEquals(Hidden::class, $annotations[1]->type); $this->assertEquals('hidden', $annotations[1]->name); creator: $annotations = $commentParser->getPropertyAnnotations($intf->getProperty('creator')); $this->assertCount(4, $annotations); $this->assertInstanceOf(Column::class, $annotations[0]); $this->assertEquals('creator_id', $annotations[0]->name); $this->assertNull($annotations[0]->default); $this->assertEquals(['creator_name'], $annotations[0]->optFields); $this->assertInstanceOf(Alias::class, $annotations[1]); $this->assertEquals('creator_id', $annotations[1]->name); $this->assertEquals(['maintener_id'], $annotations[1]->alias); $this->assertInstanceOf(Alias::class, $annotations[2]); $this->assertEquals('creator_name', $annotations[2]->name); $this->assertEquals(['maintener_name'], $annotations[2]->alias); $this->assertInstanceOf(ColumnType::class, $annotations[3]); $this->assertEquals(Target\Editor::class, $annotations[3]->type); $this->assertEquals('creator', $annotations[3]->name); }
public function testReset() { $foo = $this->getMock('JMS\\TranslationBundle\\Translation\\ExtractorInterface'); $logger = new NullLogger(); $extractor = new FileExtractor(new \Twig_Environment(), $logger, array()); $extractor->setExcludedNames(array('foo', 'bar')); $extractor->setExcludedDirs(array('baz')); $manager = $this->getManager($extractor, array('foo' => $foo)); $manager->setEnabledExtractors(array('foo' => true)); $manager->setDirectories(array('/')); $managerReflection = new \ReflectionClass($manager); $extractorReflection = new \ReflectionClass($extractor); $enabledExtractorsProperty = $managerReflection->getProperty('enabledExtractors'); $enabledExtractorsProperty->setAccessible(true); $directoriesProperty = $managerReflection->getProperty('directories'); $directoriesProperty->setAccessible(true); $excludedNamesProperty = $extractorReflection->getProperty('excludedNames'); $excludedNamesProperty->setAccessible(true); $excludedDirsProperty = $extractorReflection->getProperty('excludedDirs'); $excludedDirsProperty->setAccessible(true); $this->assertEquals(array('foo' => true), $enabledExtractorsProperty->getValue($manager)); $this->assertEquals(array('/'), $directoriesProperty->getValue($manager)); $this->assertEquals(array('foo', 'bar'), $excludedNamesProperty->getValue($extractor)); $this->assertEquals(array('baz'), $excludedDirsProperty->getValue($extractor)); $manager->reset(); $this->assertEquals(array(), $enabledExtractorsProperty->getValue($manager)); $this->assertEquals(array(), $directoriesProperty->getValue($manager)); $this->assertEquals(array(), $excludedNamesProperty->getValue($extractor)); $this->assertEquals(array(), $excludedDirsProperty->getValue($extractor)); }
/** * Testing annotations. * * @test * @covers \Bairwell\Hydrator\Annotations\From */ public function testAnnotations() { $sut = new From(); $reflection = new \ReflectionClass($sut); $this->assertTrue($reflection->isFinal()); $properties = $reflection->getDefaultProperties(); $expectedProperties = ['sources' => [], 'field' => null, 'conditions' => []]; foreach ($expectedProperties as $k => $v) { $this->assertArrayHasKey($k, $properties); $this->assertEquals($v, $properties[$k]); } $comments = $reflection->getDocComment(); $expected = preg_quote('@Annotation'); $results = preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches); $this->assertEquals(1, $results); $expected = preg_quote('@Target({"PROPERTY"})'); $this->assertEquals(1, preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches)); // $property = $reflection->getProperty('sources'); $comments = $property->getDocComment(); $expected = '@var\\s+array'; $this->assertEquals(1, preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches)); $expected = '@Required'; $this->assertEquals(1, preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches)); // field $property = $reflection->getProperty('field'); $comments = $property->getDocComment(); $expected = '@var\\s+string'; $this->assertEquals(1, preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches)); // conditions $property = $reflection->getProperty('conditions'); $comments = $property->getDocComment(); $expected = '@var\\s+array'; $this->assertEquals(1, preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches)); }
/** * Testing annotations. * * @test */ public function testAnnotations() { $sut = new AsFloat(); $reflection = new \ReflectionClass($sut); $comments = $reflection->getDocComment(); $expected = preg_quote('@Annotation'); $results = preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches); $this->assertEquals(1, $results); $expected = preg_quote('@Target({"PROPERTY"})'); $this->assertEquals(1, preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches)); $property = $reflection->getProperty('allowNull'); $comments = $property->getDocComment(); $expected = preg_quote('@var ') . '(bool|boolean)'; $this->assertEquals(1, preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches)); // $property = $reflection->getProperty('precision'); $comments = $property->getDocComment(); $expected = preg_quote('@var ') . '(int|integer)'; $this->assertEquals(1, preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches)); // $property = $reflection->getProperty('decimalSeparator'); $comments = $property->getDocComment(); $expected = preg_quote('@var ') . '(str|string)'; $this->assertEquals(1, preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches)); // $property = $reflection->getProperty('digitsSeparator'); $comments = $property->getDocComment(); $expected = preg_quote('@var ') . '(str|string)'; $this->assertEquals(1, preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches)); }
/** * {@inheritdoc} */ public function hydrate($document, MetaInformationInterface $metaInformation) { $targetEntity = $metaInformation->getEntity(); $reflectionClass = new \ReflectionClass($targetEntity); foreach ($document as $property => $value) { if ($property === MetaInformationInterface::DOCUMENT_KEY_FIELD_NAME) { $value = $this->removePrefixedKeyFieldName($value); } // skip field if value is array or "flat" object // hydrated object should contain a list of real entities / entity if ($this->mapValue($property, $value, $metaInformation) == false) { continue; } try { $classProperty = $reflectionClass->getProperty($this->removeFieldSuffix($property)); } catch (\ReflectionException $e) { try { $classProperty = $reflectionClass->getProperty($this->toCamelCase($this->removeFieldSuffix($property))); } catch (\ReflectionException $e) { continue; } } $classProperty->setAccessible(true); $classProperty->setValue($targetEntity, $value); } return $targetEntity; }
/** * test proxy setting * * @return void */ public function testSetProxy() { $query = $this->getInstance(); $query->useProxy(true); $reflection = new \ReflectionClass(get_class($query)); $propertyProxy = $reflection->getProperty('proxy'); $propertyProxy->setAccessible(true); $proxy = $propertyProxy->getValue($query); $propertyDynamic = $reflection->getProperty('dynamic'); $propertyDynamic->setAccessible(true); $dynamic = $propertyDynamic->getValue($query); $this->assertTrue($proxy); $this->assertTrue($dynamic); $query->useProxy(false); $proxy = $propertyProxy->getValue($query); $this->assertFalse($proxy); $query->useDynamic(false); $dynamic = $propertyDynamic->getValue($query); $this->assertFalse($dynamic); $setOptions = ['option1', 'option2']; $query->setProxyOption($setOptions); $property = $reflection->getProperty('options'); $property->setAccessible(true); $options = $property->getValue($query); $this->assertEquals($setOptions, $options); $query->useProxy(true); $proxyManager = m::mock('Xpressengine\\Database\\ProxyManager'); $proxyManager->shouldReceive('set'); $this->connector->shouldReceive('getProxyManager')->andReturn($proxyManager); $this->assertNull($query->getProxyManager()); $query->useDynamic(true); $this->assertInstanceOf('Xpressengine\\Database\\ProxyManager', $query->getProxyManager()); }
protected function validateRanges($ranges, AbstractDateRangeConstraint $constraint) { // Check value if (!is_array($ranges) && !$ranges instanceof \Traversable) { throw new UnexpectedTypeException($ranges, 'array or \\Traversable or \\ArrayAccess'); } $checkedRanges = []; $invalidRanges = []; foreach ($ranges as $range) { switch (false) { case property_exists($range, $constraint->startDateField): throw new ConstraintDefinitionException(sprintf('There isn`t field %s in entity %s', $constraint->startDateField, get_class($range))); case property_exists($range, $constraint->endDateField): throw new ConstraintDefinitionException(sprintf('There isn`t field %s in entity %s', $constraint->endDateField, get_class($range))); } $class = new \ReflectionClass($range); $startFieldProperty = $class->getProperty($constraint->startDateField); $endFieldProperty = $class->getProperty($constraint->endDateField); $startFieldProperty->setAccessible(true); $endFieldProperty->setAccessible(true); $startDate = $startFieldProperty->getValue($range); $endDate = $endFieldProperty->getValue($range); foreach ($checkedRanges as $checkedRange) { if ($checkedRange['start'] <= $endDate && $checkedRange['end'] >= $startDate) { $invalidRanges[] = sprintf('%s - %s', $checkedRange['start']->format('Y-m-d'), $checkedRange['end']->format('Y-m-d')); $invalidRanges[] = sprintf('%s - %s', $startDate->format('Y-m-d'), $endDate->format('Y-m-d')); } } $checkedRanges[] = ['start' => $startDate, 'end' => $endDate]; } return array_unique($invalidRanges); }
public function testStaticContent() { $data = array( 'name' => 'test-node', 'title' => 'test-title', 'body' => 'test-body', 'publishable' => false, 'publishStartDate' => new \DateTime('2013-06-18'), 'publishEndDate' => new \DateTime('2013-06-18'), ); $content = new StaticContent; $refl = new \ReflectionClass($content); $content->setParentDocument($this->base); foreach ($data as $key => $value) { $refl = new \ReflectionClass($content); $prop = $refl->getProperty($key); $prop->setAccessible(true); $prop->setValue($content, $value); } $this->dm->persist($content); $this->dm->flush(); $this->dm->clear(); $content = $this->dm->find(null, '/test/test-node'); $this->assertNotNull($content); foreach ($data as $key => $value) { $prop = $refl->getProperty($key); $prop->setAccessible(true); $v = $prop->getValue($content); if (!is_object($value)) { $this->assertEquals($value, $v); } } // test publish start and end $publishStartDate = $content->getPublishStartDate(); $publishEndDate = $content->getPublishEndDate(); $this->assertInstanceOf('\DateTime', $publishStartDate); $this->assertInstanceOf('\DateTime', $publishEndDate); $this->assertEquals($data['publishStartDate']->format('Y-m-d'), $publishStartDate->format('Y-m-d')); $this->assertEquals($data['publishEndDate']->format('Y-m-d'), $publishEndDate->format('Y-m-d')); // test multi-lang $content->setLocale('fr'); $this->dm->persist($content); $this->dm->flush(); $this->dm->clear(); $content = $this->dm->findTranslation(null, '/test/test-node', 'fr'); $this->assertEquals('fr', $content->getLocale()); }
public function setUp() { $reflClass = new \ReflectionClass(UniqueValueResolver::class); $this->resolverRefl = $reflClass->getProperty('resolver'); $this->resolverRefl->setAccessible(true); $this->poolRefl = $reflClass->getProperty('pool'); $this->poolRefl->setAccessible(true); }
public function onLoad() { $reflectionLevel = new \ReflectionClass(Level::class); $this->randomTickBlocksProperty = $reflectionLevel->getProperty("randomTickBlocks"); $this->randomTickBlocksProperty->setAccessible(true); $this->chunksPerTickProperty = $reflectionLevel->getProperty("chunksPerTick"); $this->chunksPerTickProperty->setAccessible(true); }
/** * */ public function testSetEntity() { $dumpEntity = new DumpEntity(); $this->dumpManager->setEntity($dumpEntity); $dumpEntityReflection = $this->reflectionClass->getProperty('dumpEntity'); $dumpEntityReflection->setAccessible(true); $this->assertEquals($dumpEntityReflection->getValue($this->dumpManager), $dumpEntity); }
/** * */ protected function setMockFields() { $this->webDirectory = $this->reflectionClass->getProperty('webDirectory'); $this->webDirectory->setAccessible(true); $this->webDirectory->setValue($this->command, $this->webPath); $this->filesystemField = $this->reflectionClass->getProperty('filesystem'); $this->filesystemField->setAccessible(true); }
public function testMenuNode() { $data = array('name' => 'test-node', 'label' => 'label_foobar', 'uri' => 'http://www.example.com/foo', 'route' => 'foo_route', 'linkType' => 'route', 'content' => $this->content, 'publishable' => false, 'publishStartDate' => new \DateTime('2013-06-18'), 'publishEndDate' => new \DateTime('2013-06-18'), 'attributes' => array('attr_foobar_1' => 'barfoo', 'attr_foobar_2' => 'barfoo'), 'childrenAttributes' => array('child_foobar_1' => 'barfoo', 'child_foobar_2' => 'barfoo'), 'linkAttributes' => array('link_foobar_1' => 'barfoo', 'link_foobar_2' => 'barfoo'), 'labelAttributes' => array('label_foobar_1' => 'barfoo', 'label_foobar_2' => 'barfoo'), 'extras' => array('extra_foobar_1' => 'barfoo', 'extra_foobar_2' => 'barfoo'), 'routeParameters' => array('route_param_foobar_1' => 'barfoo', 'route_param_foobar_2' => 'barfoo'), 'routeAbsolute' => true, 'display' => false, 'displayChildren' => false); $startDateString = $data['publishStartDate']->format('Y-m-d'); $endDateString = $data['publishEndDate']->format('Y-m-d'); $menuNode = new MenuNode(); $refl = new \ReflectionClass($menuNode); $menuNode->setParentDocument($this->rootDocument); foreach ($data as $key => $value) { $refl = new \ReflectionClass($menuNode); $prop = $refl->getProperty($key); $prop->setAccessible(true); $prop->setValue($menuNode, $value); } $menuNode->addChild($this->child1); $this->dm->persist($menuNode); $this->dm->flush(); $this->dm->clear(); $menuNode = $this->dm->find(null, '/test/test-node'); $this->assertNotNull($menuNode); foreach ($data as $key => $value) { $prop = $refl->getProperty($key); $prop->setAccessible(true); $v = $prop->getValue($menuNode); if (!is_object($value)) { $this->assertEquals($value, $v); } } // test objects $prop = $refl->getProperty('content'); $prop->setAccessible(true); $content = $prop->getValue($menuNode); $this->assertEquals('fake_weak_content', $content->getName()); // test children $this->assertCount(1, $menuNode->getChildren()); // test publish start and end $publishStartDate = $menuNode->getPublishStartDate(); $publishEndDate = $menuNode->getPublishEndDate(); $this->assertInstanceOf('\\DateTime', $publishStartDate); $this->assertInstanceOf('\\DateTime', $publishEndDate); $this->assertEquals($startDateString, $publishStartDate->format('Y-m-d')); $this->assertEquals($endDateString, $publishEndDate->format('Y-m-d')); // test multi-lang $menuNode->setLocale('fr'); $this->dm->persist($menuNode); $this->dm->flush(); $this->dm->clear(); $menuNode = $this->dm->findTranslation(null, '/test/test-node', 'fr'); $this->assertEquals('fr', $menuNode->getLocale()); $child = $this->dm->find(null, '/test/test-node/child1'); $menuNode = $child->getParent(); $this->assertCount(1, $menuNode->getChildren()); $menuNode->removeChild($child); $this->dm->flush(); $this->dm->clear(); $menuNode = $this->dm->find(null, '/test/test-node'); $this->assertCount(0, $menuNode->getChildren()); }
/** * @param string $field * @param mixed $value * * @throws DocumentManagerException */ public function set($field, $value) { if (!$this->has($field)) { throw new DocumentManagerException(sprintf('Document "%s" must have property "%s" (it is probably required by a behavior)', get_class($this->document), $field)); } $property = $this->reflection->getProperty($field); $property->setAccessible(true); $property->setValue($this->document, $value); }
public function setUp() { $this->trait = $this->getMockBuilder(WritableCollectionTrait::class)->getMockForTrait(); $class = new ReflectionClass($this->trait); $this->collection = $class->getProperty('collection'); $this->collection->setAccessible(true); $this->lazy = $class->getProperty('lazy'); $this->lazy->setAccessible(true); }
/** * @dataProvider canBindServiceDataProvider * @param $name * @param $binding */ public function testCanBindService($name, $binding) { $this->containerMock->bind($name, $binding); $property = $this->containerReflector->getProperty('objects'); $property->setAccessible(true); $objects = $property->getValue($this->containerMock); $this->assertArrayHasKey($name, $objects); $this->assertEquals($binding, $objects[$name]); }
public function __construct() { parent::__construct(); $this->load->config('ion_auth', TRUE); //initialize db tables data $this->tables = $this->config->item('tables', 'ion_auth'); //initialize data $this->identity_column = $this->config->item('identity', 'ion_auth'); $this->store_salt = $this->config->item('store_salt', 'ion_auth'); $this->salt_length = $this->config->item('salt_length', 'ion_auth'); $this->join = $this->config->item('join', 'ion_auth'); //initialize hash method options (Bcrypt) $this->hash_method = $this->config->item('hash_method', 'ion_auth'); $this->default_rounds = $this->config->item('default_rounds', 'ion_auth'); $this->random_rounds = $this->config->item('random_rounds', 'ion_auth'); $this->min_rounds = $this->config->item('min_rounds', 'ion_auth'); $this->max_rounds = $this->config->item('max_rounds', 'ion_auth'); //initialize messages and error $this->messages = array(); $this->errors = array(); $delimiters_source = $this->config->item('delimiters_source', 'ion_auth'); //load the error delimeters either from the config file or use what's been supplied to form validation if ($delimiters_source === 'form_validation') { //load in delimiters from form_validation //to keep this simple we'll load the value using reflection since these properties are protected $this->load->library('form_validation'); $form_validation_class = new ReflectionClass("CI_Form_validation"); $error_prefix = $form_validation_class->getProperty("_error_prefix"); $error_prefix->setAccessible(TRUE); $this->error_start_delimiter = $error_prefix->getValue($this->form_validation); $this->message_start_delimiter = $this->error_start_delimiter; $error_suffix = $form_validation_class->getProperty("_error_suffix"); $error_suffix->setAccessible(TRUE); $this->error_end_delimiter = $error_suffix->getValue($this->form_validation); $this->message_end_delimiter = $this->error_end_delimiter; } else { //use delimiters from config $this->message_start_delimiter = $this->config->item('message_start_delimiter', 'ion_auth'); $this->message_end_delimiter = $this->config->item('message_end_delimiter', 'ion_auth'); $this->error_start_delimiter = $this->config->item('error_start_delimiter', 'ion_auth'); $this->error_end_delimiter = $this->config->item('error_end_delimiter', 'ion_auth'); } //initialize our hooks object $this->_ion_hooks = new stdClass(); //load the bcrypt class if needed if ($this->hash_method == 'bcrypt') { if ($this->random_rounds) { $rand = rand($this->min_rounds, $this->max_rounds); $rounds = array('rounds' => $rand); } else { $rounds = array('rounds' => $this->default_rounds); } $this->load->library('bcrypt', $rounds); } $this->trigger_events('model_constructor'); }
/** * Test loading with a good API connection. * @covers Client::setUrl($url) * @covers Client::setAccessToken($accessToken) * @test */ public function testConfigure() { $reflection = new \ReflectionClass('Clicksign\\Client'); $url = $reflection->getProperty("url"); $url->setAccessible(true); $accessToken = $reflection->getProperty("accessToken"); $accessToken->setAccessible(true); $this->assertEquals('http://example.com/', $url->getValue($this->client)); $this->assertEquals('my_token', $accessToken->getValue($this->client)); }
/** * Get $object private/protected property value. * * @param string $property Private/protected property name * * @param object $object Object instance for getting private/protected property value * * @return mixed Private/protected property value */ protected function getProperty($property, $object) { $environmentProperty = $this->reflection->getProperty($property); $environmentProperty->setAccessible(true); try { return $environmentProperty->getValue($object); } catch (\Exception $e) { return null; } }
/** * @dataProvider getSignatureProvider */ public function testGetSignature($args, $expected) { $property = $this->reflectionClass->getProperty('args'); $property->setAccessible(true); $property->setValue($this->inst, $args); $method = $this->reflectionClass->getMethod('getSignature'); $method->setAccessible(true); $actual = $method->invoke($this->inst); $this->assertEquals($expected, $actual); }
/** * @param array $data */ protected function fill(array &$data) { static $className, $methods, $vars, $reflection; if (!$className) { $className = get_class($this); $methods = get_class_methods($className); $vars = array_keys(get_class_vars($className)); $reflection = new \ReflectionClass($className); } foreach ($data as $k => $v) { if ($k == "@attributes") { continue; } $methodName = 'set' . ucfirst($k); if (in_array($methodName, $methods)) { $this->{$methodName}($v); continue; } $methodName = 'set' . ucfirst($this->removeNameSpaceFromVariableName($k)); if (in_array($methodName, $methods)) { $this->{$methodName}($v); continue; } $varName = lcfirst($this->removeNameSpaceFromVariableName($k)); if (in_array($varName, $vars)) { $docComment = $reflection->getProperty($varName)->getDocComment(); if (preg_match('/@var ([\\\\]?[A-Z]\\S+)/s', $docComment, $annotations)) { $varClassName = $annotations[1]; if (class_exists($varClassName)) { $v = new $varClassName($v, $this->saveOriginalData); } } $this->{$varName} = $v; continue; } $varName .= "s"; if (in_array($varName, $vars)) { $docComment = $reflection->getProperty($varName)->getDocComment(); if ($annotations = self::parse('/@var\\s+([\\\\]?[A-Z]\\S+)(\\[\\])/s', $docComment)) { $varClassName = $annotations[1]; if (class_exists($varClassName)) { $items = array(); $isNumeric = is_int(key($v)); $list = $isNumeric ? $v : array($v); foreach ($list as $subData) { $items[] = new $varClassName($subData, $this->saveOriginalData); } $v = $items; } } $this->{$varName} = $v; continue; } } }