How to use fromArray method of Meta class

Best Cucumber Common Library code snippet using Meta.fromArray

PhpModuleDatetimeImmutableTest.php

Source:PhpModuleDatetimeImmutableTest.php Github

copy

Full Screen

...58 }59 public function testClassWithNoPropertyFromArray()60 {61 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\Meta\\ClassWithNoPropertyMeta", ClassWithNoPropertyMeta::getInstance());62 $instance = ClassWithNoPropertyMeta::fromArray(array());63 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\ClassWithNoProperty", $instance);64 $this->assertSame($instance, ClassWithNoPropertyMeta::fromArray(array(), null, $instance));65 }66 public function testClassWithNoPropertyToArray()67 {68 $instance = new ClassWithNoProperty();69 $array = ClassWithNoPropertyMeta::toArray($instance);70 $this->assertEmpty($array);71 }72 public function testClassWithPublicPropertyFromArray()73 {74 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\Meta\\ClassWithPublicPropertyMeta", ClassWithPublicPropertyMeta::getInstance());75 $instance = ClassWithPublicPropertyMeta::fromArray(array("property" => "value"));76 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\ClassWithPublicProperty", $instance);77 $this->assertEquals("value", $instance->property);78 $this->assertSame($instance, ClassWithPublicPropertyMeta::fromArray(array(), null, $instance));79 }80 public function testClassWithPublicPropertyToArray()81 {82 $instance = new ClassWithPublicProperty();83 $instance->property = "some value";84 $array = ClassWithPublicPropertyMeta::toArray($instance);85 $this->assertNotEmpty($array);86 $this->assertArrayHasKey("property", $array);87 $this->assertEquals("some value", $array["property"]);88 }89 public function testClassWithProtectedPropertyFromArray()90 {91 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\Meta\\ClassWithProtectedPropertyMeta", ClassWithProtectedPropertyMeta::getInstance());92 $instance = ClassWithProtectedPropertyMeta::fromArray(array("property" => "value"));93 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\ClassWithProtectedProperty", $instance);94 $this->assertEquals("value", $instance->getProperty());95 $this->assertSame($instance, ClassWithProtectedPropertyMeta::fromArray(array(), null, $instance));96 }97 public function testClassWithProtectedPropertyToArray()98 {99 $instance = new ClassWithProtectedProperty();100 $instance->setProperty("some value");101 $array = ClassWithProtectedPropertyMeta::toArray($instance);102 $this->assertNotEmpty($array);103 $this->assertArrayHasKey("property", $array);104 $this->assertEquals("some value", $array["property"]);105 }106 public function testClassWithPrivatePropertyFromArray()107 {108 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\Meta\\ClassWithPrivatePropertyMeta", ClassWithPrivatePropertyMeta::getInstance());109 $instance = ClassWithPrivatePropertyMeta::fromArray(array("property" => "value"));110 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\ClassWithPrivateProperty", $instance);111 $this->assertNull($instance->getProperty());112 $this->assertSame($instance, ClassWithPrivatePropertyMeta::fromArray(array(), null, $instance));113 }114 public function testClassWithPrivatePropertyToArray()115 {116 $instance = new ClassWithPrivateProperty();117 $instance->setProperty("some value");118 $array = ClassWithPrivatePropertyMeta::toArray($instance);119 $this->assertEmpty($array);120 $this->assertArrayNotHasKey("property", $array);121 }122 public function testClassWithCustomOffsetPropertyFromArray()123 {124 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\Meta\\ClassWithCustomOffsetPropertyMeta", ClassWithCustomOffsetPropertyMeta::getInstance());125 $instance = ClassWithCustomOffsetPropertyMeta::fromArray(array("some-offset" => "value"));126 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\ClassWithCustomOffsetProperty", $instance);127 $this->assertEquals("value", $instance->property);128 $this->assertSame($instance, ClassWithCustomOffsetPropertyMeta::fromArray(array(), null, $instance));129 }130 public function testClassWithCustomOffsetPropertyToArray()131 {132 $instance = new ClassWithCustomOffsetProperty();133 $instance->property = "some value";134 $array = ClassWithCustomOffsetPropertyMeta::toArray($instance);135 $this->assertNotEmpty($array);136 $this->assertArrayHasKey("some-offset", $array);137 $this->assertEquals("some value", $array["some-offset"]);138 }139 public function testClassWithManyOffsetsPerPropertyFromArray()140 {141 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\Meta\\ClassWithManyArrayOffsetsPerPropertyMeta", ClassWithManyArrayOffsetsPerPropertyMeta::getInstance());142 $instance = ClassWithManyArrayOffsetsPerPropertyMeta::fromArray(array("property" => "value"));143 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\ClassWithManyArrayOffsetsPerProperty", $instance);144 $this->assertEquals("value", $instance->property);145 $this->assertSame($instance, ClassWithManyArrayOffsetsPerPropertyMeta::fromArray(array(), null, $instance));146 $instance = ClassWithManyArrayOffsetsPerPropertyMeta::fromArray(array("foo" => "value"), "foo");147 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\ClassWithManyArrayOffsetsPerProperty", $instance);148 $this->assertEquals("value", $instance->property);149 $this->assertSame($instance, ClassWithManyArrayOffsetsPerPropertyMeta::fromArray(array(), "foo", $instance));150 $instance = ClassWithManyArrayOffsetsPerPropertyMeta::fromArray(array("bar" => "value"), "bar");151 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\ClassWithManyArrayOffsetsPerProperty", $instance);152 $this->assertEquals("value", $instance->property);153 $this->assertSame($instance, ClassWithManyArrayOffsetsPerPropertyMeta::fromArray(array(), "bar", $instance));154 }155 public function testClassWithManyOffsetsPerPropertyToArray()156 {157 $instance = new ClassWithManyArrayOffsetsPerProperty();158 $instance->property = "some value";159 $array = ClassWithManyArrayOffsetsPerPropertyMeta::toArray($instance);160 $this->assertNotEmpty($array);161 $this->assertArrayHasKey("property", $array);162 $this->assertEquals("some value", $array["property"]);163 $array = ClassWithManyArrayOffsetsPerPropertyMeta::toArray($instance, "foo");164 $this->assertNotEmpty($array);165 $this->assertArrayHasKey("foo", $array);166 $this->assertEquals("some value", $array["foo"]);167 $array = ClassWithManyArrayOffsetsPerPropertyMeta::toArray($instance, "bar");168 $this->assertNotEmpty($array);169 $this->assertArrayHasKey("bar", $array);170 $this->assertEquals("some value", $array["bar"]);171 }172 public function testClassWithPropertyReferencingClassFromArray()173 {174 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\Meta\\ClassWithPropertyReferencingClassMeta", ClassWithPropertyReferencingClassMeta::getInstance());175 $instance = ClassWithPropertyReferencingClassMeta::fromArray(array(176 "classWithPublicProperty" => array(177 "property" => "value"178 )179 ));180 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\ClassWithPropertyReferencingClass", $instance);181 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\ClassWithPublicProperty", $instance->classWithPublicProperty);182 $this->assertEquals("value", $instance->classWithPublicProperty->property);183 $instanceAgain = ClassWithPropertyReferencingClassMeta::fromArray(array(184 "classWithPublicProperty" => array(185 "property" => "other value"186 )187 ), null, $instance);188 $this->assertSame($instance, $instanceAgain);189 $this->assertSame($instance->classWithPublicProperty, $instanceAgain->classWithPublicProperty);190 }191 public function testClassWithPropertyReferencingClassToArray()192 {193 $instance = new ClassWithPropertyReferencingClass();194 $instance->classWithPublicProperty = new ClassWithPublicProperty();195 $instance->classWithPublicProperty->property = "some value";196 $array = ClassWithPropertyReferencingClassMeta::toArray($instance);197 $this->assertNotEmpty($array);198 $this->assertArrayHasKey("classWithPublicProperty", $array);199 $this->assertNotEmpty($array["classWithPublicProperty"]);200 $this->assertArrayHasKey("property", $array["classWithPublicProperty"]);201 $this->assertEquals("some value", $array["classWithPublicProperty"]["property"]);202 }203 public function testClassWithArrayPropertyFromArray()204 {205 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\Meta\\ClassWithArrayPropertyMeta", ClassWithArrayPropertyMeta::getInstance());206 $instance = ClassWithArrayPropertyMeta::fromArray(array("array" => array("foo" => array("bar" => "baz"))));207 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\ClassWithArrayProperty", $instance);208 $this->assertNotEmpty($instance->array);209 $this->assertArrayHasKey("foo", $instance->array);210 $this->assertArrayHasKey("bar", $instance->array["foo"]);211 $this->assertEquals("baz", $instance->array["foo"]["bar"]);212 $this->assertSame($instance, ClassWithArrayPropertyMeta::fromArray(array(), null, $instance));213 }214 public function testClassWithArrayPropertyToArray()215 {216 $instance = new ClassWithArrayProperty();217 $instance->array = array("foo" => array("bar" => "baz"));218 $array = ClassWithArrayPropertyMeta::toArray($instance);219 $this->assertNotEmpty($array);220 $this->assertArrayHasKey("array", $array);221 $this->assertArrayHasKey("foo", $array["array"]);222 $this->assertArrayHasKey("bar", $array["array"]["foo"]);223 $this->assertEquals("baz", $array["array"]["foo"]["bar"]);224 }225 public function testClassWithArrayPropertyFromArrayWithArrayCollection()226 {227 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\Meta\\ClassWithArrayPropertyMeta", ClassWithArrayPropertyMeta::getInstance());228 $instance = ClassWithArrayPropertyMeta::fromArray(array("array" => new ArrayCollection(array("foo" => array("bar" => "baz")))));229 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\ClassWithArrayProperty", $instance);230 $this->assertNotEmpty($instance->array);231 $this->assertArrayHasKey("foo", $instance->array);232 $this->assertArrayHasKey("bar", $instance->array["foo"]);233 $this->assertEquals("baz", $instance->array["foo"]["bar"]);234 $this->assertSame($instance, ClassWithArrayPropertyMeta::fromArray(array(), null, $instance));235 }236 public function testClassWithArrayPropertyToArrayWithArrayCollection()237 {238 $instance = new ClassWithArrayProperty();239 $instance->array = new ArrayCollection(array("foo" => array("bar" => "baz")));240 $array = ClassWithArrayPropertyMeta::toArray($instance);241 $this->assertNotEmpty($array);242 $this->assertArrayHasKey("array", $array);243 $this->assertArrayHasKey("foo", $array["array"]);244 $this->assertArrayHasKey("bar", $array["array"]["foo"]);245 $this->assertEquals("baz", $array["array"]["foo"]["bar"]);246 }247 public function testClassWithDatetimePropertyFromArray()248 {249 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\Meta\\ClassWithDatetimePropertyMeta", ClassWithDatetimePropertyMeta::getInstance());250 $d = new \DateTime();251 $instance = ClassWithDatetimePropertyMeta::fromArray(array("datetime" => $d->format("Y-m-d H:i:s")));252 $this->assertNotNull($instance->datetime);253 $this->assertEquals($d->format(\DateTime::ATOM), $instance->datetime->format(\DateTime::ATOM));254 }255 public function testClassWithDatetimePropertyToArray()256 {257 $d = new \DateTime();258 $instance = new ClassWithDatetimeProperty();259 $instance->datetime = $d;260 $array = ClassWithDatetimePropertyMeta::toArray($instance);261 $this->assertArrayHasKey("datetime", $array);262 $this->assertEquals($d->format("Y-m-d H:i:s"), $array["datetime"]);263 }264 public function testClassWithDiscriminatorMapFromArray()265 {266 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\Meta\\ClassWithDiscriminatorMapMeta", ClassWithDiscriminatorMapMeta::getInstance());267 /** @var ClassWithDiscriminatorValueA $aInstance */268 $aInstance = ClassWithDiscriminatorMapMeta::fromArray(array("value" => "a", "a" => 21, "b" => 42));269 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\ClassWithDiscriminatorValueA", $aInstance);270 $this->assertEquals("a", $aInstance->value);271 $this->assertEquals(21, $aInstance->a);272 /** @var ClassWithDiscriminatorValueB $bInstance */273 $bInstance = ClassWithDiscriminatorMapMeta::fromArray(array("value" => "b", "a" => 21, "b" => 42));274 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\ClassWithDiscriminatorValueB", $bInstance);275 $this->assertEquals("b", $bInstance->value);276 $this->assertEquals(42, $bInstance->b);277 /** @var ClassWithDiscriminatorValueA $aTopInstance */278 $aTopInstance = ClassWithDiscriminatorMapMeta::fromArray(array("a" => array("a" => 63)), "top");279 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\ClassWithDiscriminatorValueA", $aTopInstance);280 $this->assertNull($aTopInstance->value);281 $this->assertEquals(63, $aTopInstance->a);282 /** @var ClassWithDiscriminatorValueB $bTopInstance */283 $bTopInstance = ClassWithDiscriminatorMapMeta::fromArray(array("b" => array("b" => 84)), "top");284 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\ClassWithDiscriminatorValueB", $bTopInstance);285 $this->assertNull($bTopInstance->value);286 $this->assertEquals(84, $bTopInstance->b);287 }288 public function testClassWithDiscriminatorMapToArray()289 {290 $aInstance = new ClassWithDiscriminatorValueA();291 $aInstance->a = 21;292 $aArray = ClassWithDiscriminatorMapMeta::toArray($aInstance);293 $this->assertArrayHasKey("value", $aArray);294 $this->assertEquals("a", $aArray["value"]);295 $this->assertArrayHasKey("a", $aArray);296 $this->assertEquals(21, $aArray["a"]);297 $this->assertArrayNotHasKey("b", $aArray);298 $bInstance = new ClassWithDiscriminatorValueB();299 $bInstance->b = 42;300 $bArray = ClassWithDiscriminatorMapMeta::toArray($bInstance);301 $this->assertArrayHasKey("value", $bArray);302 $this->assertEquals("b", $bArray["value"]);303 $this->assertArrayHasKey("b", $bArray);304 $this->assertEquals(42, $bArray["b"]);305 $this->assertArrayNotHasKey("a", $bArray);306 }307 public function testOverwriteClassWithPublicPropertyFromArray()308 {309 $instance = new ClassWithPublicProperty();310 $instance->property = "foobar";311 $this->assertEquals("foobar", $instance->property);312 ClassWithPublicPropertyMeta::fromArray(["property" => null], null, $instance);313 $this->assertNull($instance->property);314 }315 public function testOverwriteClassWithDatetimePropertyFromArray()316 {317 $now = new \DateTime();318 $instance = new ClassWithDatetimeProperty();319 $instance->datetime = $now;320 $this->assertEquals($now, $instance->datetime);321 ClassWithDatetimePropertyMeta::fromArray(["datetime" => null], null, $instance);322 $this->assertNull($instance->datetime);323 }324 public function testOverwriteClassWithArrayPropertyFromArray()325 {326 $instance = new ClassWithArrayProperty();327 $instance->array = ["foo" => ["bar" => "baz"]];328 $this->assertEquals(["foo" => ["bar" => "baz"]], $instance->array);329 ClassWithArrayPropertyMeta::fromArray(["array" => null], null, $instance);330 $this->assertNull($instance->array);331 }332 public function testClassWithRecursiveProperty()333 {334 $a = new ClassWithRecursiveProperty();335 $a->property = $a;336 $this->assertEquals(0, count(Stack::$objects));337 $this->assertEquals(["property" => null], ClassWithRecursivePropertyMeta::toArray($a));338 $this->assertEquals(0, count(Stack::$objects));339 $b = new ClassWithRecursiveProperty();340 $a->property = $b;341 $b->property = $a;342 $this->assertEquals(0, count(Stack::$objects));343 $this->assertEquals(["property" => ["property" => null]], ClassWithRecursivePropertyMeta::toArray($a));344 $this->assertEquals(0, count(Stack::$objects));345 try {346 $b->property = "wtf";347 $this->assertEquals(0, count(Stack::$objects));348 ClassWithRecursivePropertyMeta::toArray($a);349 $this->fail("An exception should be thrown.");350 } catch (\Exception $e) {351 $this->assertEquals(0, count(Stack::$objects));352 $this->assertEquals('You have to pass object of class Skrz\Meta\Fixtures\PHP\ClassWithRecursiveProperty.', $e->getMessage());353 }354 }355 public function testClassWithMorePropertiesFiltered()356 {357 $instance = new ClassWithMoreProperties();358 $instance->a = "foo1";359 $instance->b = "foo2";360 $instance->c = "foo3";361 $instance->d = "foo4";362 $instance->e = "foo5";363 $this->assertEquals(364 [365 "a" => "foo1",366 "b" => "foo2",367 "c" => "foo3",368 "d" => "foo4",369 "e" => "foo5",370 "f" => null,371 "g" => [],372 ],373 ClassWithMorePropertiesMeta::toArray($instance)374 );375 $this->assertEquals(376 [377 "a" => "foo1",378 ],379 ClassWithMorePropertiesMeta::toArray($instance, null, [380 "a" => true,381 ])382 );383 $this->assertEquals(384 [385 "b" => "foo2",386 "c" => "foo3",387 "d" => "foo4",388 ],389 ClassWithMorePropertiesMeta::toArray($instance, null, [390 "b" => true,391 "c" => true,392 "d" => true,393 ])394 );395 $instance2 = new ClassWithMoreProperties();396 $instance2->a = "foo6";397 $instance->f = $instance2;398 $this->assertEquals(399 [400 "e" => "foo5",401 "f" => [402 "a" => "foo6",403 "b" => null,404 ],405 ],406 ClassWithMorePropertiesMeta::toArray($instance, null, [407 "e" => true,408 "f" => [409 "a" => true,410 "b" => true,411 ],412 ])413 );414 $instance3 = new ClassWithMoreProperties();415 $instance3->a = "foo7";416 $instance->g = [$instance2, $instance3];417 $this->assertEquals(418 [419 "g" => [420 [421 "a" => "foo6",422 ],423 [424 "a" => "foo7",425 ]426 ],427 ],428 ClassWithMorePropertiesMeta::toArray($instance, null, [429 "g" => [430 "a" => true,431 ],432 ])433 );434 }435 public function testClassWithMorePropertiesFilteredByFieldsFromArray()436 {437 $instance = new ClassWithMoreProperties();438 $instance->a = "foo1";439 $instance->b = "foo2";440 $instance->c = "foo3";441 $instance->d = "foo4";442 $instance->e = "foo5";443 $this->assertEquals(444 [445 "a" => "foo1",446 "b" => "foo2",447 "c" => "foo3",448 "d" => "foo4",449 "e" => "foo5",450 "f" => null,451 "g" => [],452 ],453 ClassWithMorePropertiesMeta::toArray($instance)454 );455 $this->assertEquals(456 [457 "a" => "foo1",458 ],459 ClassWithMorePropertiesMeta::toArray($instance, null, Fields::fromArray([460 "a" => true,461 ]))462 );463 $this->assertEquals(464 [465 "b" => "foo2",466 "c" => "foo3",467 "d" => "foo4",468 ],469 ClassWithMorePropertiesMeta::toArray($instance, null, Fields::fromArray([470 "b" => true,471 "c" => true,472 "d" => true,473 ]))474 );475 $instance2 = new ClassWithMoreProperties();476 $instance2->a = "foo6";477 $instance->f = $instance2;478 $this->assertEquals(479 [480 "e" => "foo5",481 "f" => [482 "a" => "foo6",483 "b" => null,484 ],485 ],486 ClassWithMorePropertiesMeta::toArray($instance, null, Fields::fromArray([487 "e" => true,488 "f" => [489 "a" => true,490 "b" => true,491 ],492 ]))493 );494 $instance3 = new ClassWithMoreProperties();495 $instance3->a = "foo7";496 $instance->g = [$instance2, $instance3];497 $this->assertEquals(498 [499 "g" => [500 [501 "a" => "foo6",502 ],503 [504 "a" => "foo7",505 ]506 ],507 ],508 ClassWithMorePropertiesMeta::toArray($instance, null, Fields::fromArray([509 "g" => [510 "a" => true,511 ],512 ]))513 );514 }515 public function testClassWithMorePropertiesFilteredByFieldsFromString()516 {517 $instance = new ClassWithMoreProperties();518 $instance->a = "foo1";519 $instance->b = "foo2";520 $instance->c = "foo3";521 $instance->d = "foo4";522 $instance->e = "foo5";...

Full Screen

Full Screen

PhpModuleTest.php

Source:PhpModuleTest.php Github

copy

Full Screen

...58 }59 public function testClassWithNoPropertyFromArray()60 {61 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\Meta\\ClassWithNoPropertyMeta", ClassWithNoPropertyMeta::getInstance());62 $instance = ClassWithNoPropertyMeta::fromArray(array());63 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\ClassWithNoProperty", $instance);64 $this->assertSame($instance, ClassWithNoPropertyMeta::fromArray(array(), null, $instance));65 }66 public function testClassWithNoPropertyToArray()67 {68 $instance = new ClassWithNoProperty();69 $array = ClassWithNoPropertyMeta::toArray($instance);70 $this->assertEmpty($array);71 }72 public function testClassWithPublicPropertyFromArray()73 {74 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\Meta\\ClassWithPublicPropertyMeta", ClassWithPublicPropertyMeta::getInstance());75 $instance = ClassWithPublicPropertyMeta::fromArray(array("property" => "value"));76 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\ClassWithPublicProperty", $instance);77 $this->assertEquals("value", $instance->property);78 $this->assertSame($instance, ClassWithPublicPropertyMeta::fromArray(array(), null, $instance));79 }80 public function testClassWithPublicPropertyToArray()81 {82 $instance = new ClassWithPublicProperty();83 $instance->property = "some value";84 $array = ClassWithPublicPropertyMeta::toArray($instance);85 $this->assertNotEmpty($array);86 $this->assertArrayHasKey("property", $array);87 $this->assertEquals("some value", $array["property"]);88 }89 public function testClassWithProtectedPropertyFromArray()90 {91 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\Meta\\ClassWithProtectedPropertyMeta", ClassWithProtectedPropertyMeta::getInstance());92 $instance = ClassWithProtectedPropertyMeta::fromArray(array("property" => "value"));93 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\ClassWithProtectedProperty", $instance);94 $this->assertEquals("value", $instance->getProperty());95 $this->assertSame($instance, ClassWithProtectedPropertyMeta::fromArray(array(), null, $instance));96 }97 public function testClassWithProtectedPropertyToArray()98 {99 $instance = new ClassWithProtectedProperty();100 $instance->setProperty("some value");101 $array = ClassWithProtectedPropertyMeta::toArray($instance);102 $this->assertNotEmpty($array);103 $this->assertArrayHasKey("property", $array);104 $this->assertEquals("some value", $array["property"]);105 }106 public function testClassWithPrivatePropertyFromArray()107 {108 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\Meta\\ClassWithPrivatePropertyMeta", ClassWithPrivatePropertyMeta::getInstance());109 $instance = ClassWithPrivatePropertyMeta::fromArray(array("property" => "value"));110 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\ClassWithPrivateProperty", $instance);111 $this->assertNull($instance->getProperty());112 $this->assertSame($instance, ClassWithPrivatePropertyMeta::fromArray(array(), null, $instance));113 }114 public function testClassWithPrivatePropertyToArray()115 {116 $instance = new ClassWithPrivateProperty();117 $instance->setProperty("some value");118 $array = ClassWithPrivatePropertyMeta::toArray($instance);119 $this->assertEmpty($array);120 $this->assertArrayNotHasKey("property", $array);121 }122 public function testClassWithCustomOffsetPropertyFromArray()123 {124 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\Meta\\ClassWithCustomOffsetPropertyMeta", ClassWithCustomOffsetPropertyMeta::getInstance());125 $instance = ClassWithCustomOffsetPropertyMeta::fromArray(array("some-offset" => "value"));126 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\ClassWithCustomOffsetProperty", $instance);127 $this->assertEquals("value", $instance->property);128 $this->assertSame($instance, ClassWithCustomOffsetPropertyMeta::fromArray(array(), null, $instance));129 }130 public function testClassWithCustomOffsetPropertyToArray()131 {132 $instance = new ClassWithCustomOffsetProperty();133 $instance->property = "some value";134 $array = ClassWithCustomOffsetPropertyMeta::toArray($instance);135 $this->assertNotEmpty($array);136 $this->assertArrayHasKey("some-offset", $array);137 $this->assertEquals("some value", $array["some-offset"]);138 }139 public function testClassWithManyOffsetsPerPropertyFromArray()140 {141 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\Meta\\ClassWithManyArrayOffsetsPerPropertyMeta", ClassWithManyArrayOffsetsPerPropertyMeta::getInstance());142 $instance = ClassWithManyArrayOffsetsPerPropertyMeta::fromArray(array("property" => "value"));143 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\ClassWithManyArrayOffsetsPerProperty", $instance);144 $this->assertEquals("value", $instance->property);145 $this->assertSame($instance, ClassWithManyArrayOffsetsPerPropertyMeta::fromArray(array(), null, $instance));146 $instance = ClassWithManyArrayOffsetsPerPropertyMeta::fromArray(array("foo" => "value"), "foo");147 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\ClassWithManyArrayOffsetsPerProperty", $instance);148 $this->assertEquals("value", $instance->property);149 $this->assertSame($instance, ClassWithManyArrayOffsetsPerPropertyMeta::fromArray(array(), "foo", $instance));150 $instance = ClassWithManyArrayOffsetsPerPropertyMeta::fromArray(array("bar" => "value"), "bar");151 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\ClassWithManyArrayOffsetsPerProperty", $instance);152 $this->assertEquals("value", $instance->property);153 $this->assertSame($instance, ClassWithManyArrayOffsetsPerPropertyMeta::fromArray(array(), "bar", $instance));154 }155 public function testClassWithManyOffsetsPerPropertyToArray()156 {157 $instance = new ClassWithManyArrayOffsetsPerProperty();158 $instance->property = "some value";159 $array = ClassWithManyArrayOffsetsPerPropertyMeta::toArray($instance);160 $this->assertNotEmpty($array);161 $this->assertArrayHasKey("property", $array);162 $this->assertEquals("some value", $array["property"]);163 $array = ClassWithManyArrayOffsetsPerPropertyMeta::toArray($instance, "foo");164 $this->assertNotEmpty($array);165 $this->assertArrayHasKey("foo", $array);166 $this->assertEquals("some value", $array["foo"]);167 $array = ClassWithManyArrayOffsetsPerPropertyMeta::toArray($instance, "bar");168 $this->assertNotEmpty($array);169 $this->assertArrayHasKey("bar", $array);170 $this->assertEquals("some value", $array["bar"]);171 }172 public function testClassWithPropertyReferencingClassFromArray()173 {174 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\Meta\\ClassWithPropertyReferencingClassMeta", ClassWithPropertyReferencingClassMeta::getInstance());175 $instance = ClassWithPropertyReferencingClassMeta::fromArray(array(176 "classWithPublicProperty" => array(177 "property" => "value"178 )179 ));180 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\ClassWithPropertyReferencingClass", $instance);181 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\ClassWithPublicProperty", $instance->classWithPublicProperty);182 $this->assertEquals("value", $instance->classWithPublicProperty->property);183 $instanceAgain = ClassWithPropertyReferencingClassMeta::fromArray(array(184 "classWithPublicProperty" => array(185 "property" => "other value"186 )187 ), null, $instance);188 $this->assertSame($instance, $instanceAgain);189 $this->assertSame($instance->classWithPublicProperty, $instanceAgain->classWithPublicProperty);190 }191 public function testClassWithPropertyReferencingClassToArray()192 {193 $instance = new ClassWithPropertyReferencingClass();194 $instance->classWithPublicProperty = new ClassWithPublicProperty();195 $instance->classWithPublicProperty->property = "some value";196 $array = ClassWithPropertyReferencingClassMeta::toArray($instance);197 $this->assertNotEmpty($array);198 $this->assertArrayHasKey("classWithPublicProperty", $array);199 $this->assertNotEmpty($array["classWithPublicProperty"]);200 $this->assertArrayHasKey("property", $array["classWithPublicProperty"]);201 $this->assertEquals("some value", $array["classWithPublicProperty"]["property"]);202 }203 public function testClassWithArrayPropertyFromArray()204 {205 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\Meta\\ClassWithArrayPropertyMeta", ClassWithArrayPropertyMeta::getInstance());206 $instance = ClassWithArrayPropertyMeta::fromArray(array("array" => array("foo" => array("bar" => "baz"))));207 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\ClassWithArrayProperty", $instance);208 $this->assertNotEmpty($instance->array);209 $this->assertArrayHasKey("foo", $instance->array);210 $this->assertArrayHasKey("bar", $instance->array["foo"]);211 $this->assertEquals("baz", $instance->array["foo"]["bar"]);212 $this->assertSame($instance, ClassWithArrayPropertyMeta::fromArray(array(), null, $instance));213 }214 public function testClassWithArrayPropertyToArray()215 {216 $instance = new ClassWithArrayProperty();217 $instance->array = array("foo" => array("bar" => "baz"));218 $array = ClassWithArrayPropertyMeta::toArray($instance);219 $this->assertNotEmpty($array);220 $this->assertArrayHasKey("array", $array);221 $this->assertArrayHasKey("foo", $array["array"]);222 $this->assertArrayHasKey("bar", $array["array"]["foo"]);223 $this->assertEquals("baz", $array["array"]["foo"]["bar"]);224 }225 public function testClassWithArrayPropertyFromArrayWithArrayCollection()226 {227 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\Meta\\ClassWithArrayPropertyMeta", ClassWithArrayPropertyMeta::getInstance());228 $instance = ClassWithArrayPropertyMeta::fromArray(array("array" => new ArrayCollection(array("foo" => array("bar" => "baz")))));229 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\ClassWithArrayProperty", $instance);230 $this->assertNotEmpty($instance->array);231 $this->assertArrayHasKey("foo", $instance->array);232 $this->assertArrayHasKey("bar", $instance->array["foo"]);233 $this->assertEquals("baz", $instance->array["foo"]["bar"]);234 $this->assertSame($instance, ClassWithArrayPropertyMeta::fromArray(array(), null, $instance));235 }236 public function testClassWithArrayPropertyToArrayWithArrayCollection()237 {238 $instance = new ClassWithArrayProperty();239 $instance->array = new ArrayCollection(array("foo" => array("bar" => "baz")));240 $array = ClassWithArrayPropertyMeta::toArray($instance);241 $this->assertNotEmpty($array);242 $this->assertArrayHasKey("array", $array);243 $this->assertArrayHasKey("foo", $array["array"]);244 $this->assertArrayHasKey("bar", $array["array"]["foo"]);245 $this->assertEquals("baz", $array["array"]["foo"]["bar"]);246 }247 public function testClassWithDatetimePropertyFromArray()248 {249 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\Meta\\ClassWithDatetimePropertyMeta", ClassWithDatetimePropertyMeta::getInstance());250 $d = new \DateTime();251 $instance = ClassWithDatetimePropertyMeta::fromArray(array("datetime" => $d->format("Y-m-d H:i:s")));252 $this->assertNotNull($instance->datetime);253 $this->assertEquals($d->format(\DateTime::ATOM), $instance->datetime->format(\DateTime::ATOM));254 }255 public function testClassWithDatetimePropertyToArray()256 {257 $d = new \DateTime();258 $instance = new ClassWithDatetimeProperty();259 $instance->datetime = $d;260 $array = ClassWithDatetimePropertyMeta::toArray($instance);261 $this->assertArrayHasKey("datetime", $array);262 $this->assertEquals($d->format("Y-m-d H:i:s"), $array["datetime"]);263 }264 public function testClassWithDiscriminatorMapFromArray()265 {266 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\Meta\\ClassWithDiscriminatorMapMeta", ClassWithDiscriminatorMapMeta::getInstance());267 /** @var ClassWithDiscriminatorValueA $aInstance */268 $aInstance = ClassWithDiscriminatorMapMeta::fromArray(array("value" => "a", "a" => 21, "b" => 42));269 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\ClassWithDiscriminatorValueA", $aInstance);270 $this->assertEquals("a", $aInstance->value);271 $this->assertEquals(21, $aInstance->a);272 /** @var ClassWithDiscriminatorValueB $bInstance */273 $bInstance = ClassWithDiscriminatorMapMeta::fromArray(array("value" => "b", "a" => 21, "b" => 42));274 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\ClassWithDiscriminatorValueB", $bInstance);275 $this->assertEquals("b", $bInstance->value);276 $this->assertEquals(42, $bInstance->b);277 /** @var ClassWithDiscriminatorValueA $aTopInstance */278 $aTopInstance = ClassWithDiscriminatorMapMeta::fromArray(array("a" => array("a" => 63)), "top");279 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\ClassWithDiscriminatorValueA", $aTopInstance);280 $this->assertNull($aTopInstance->value);281 $this->assertEquals(63, $aTopInstance->a);282 /** @var ClassWithDiscriminatorValueB $bTopInstance */283 $bTopInstance = ClassWithDiscriminatorMapMeta::fromArray(array("b" => array("b" => 84)), "top");284 $this->assertInstanceOf("Skrz\\Meta\\Fixtures\\PHP\\ClassWithDiscriminatorValueB", $bTopInstance);285 $this->assertNull($bTopInstance->value);286 $this->assertEquals(84, $bTopInstance->b);287 }288 public function testClassWithDiscriminatorMapToArray()289 {290 $aInstance = new ClassWithDiscriminatorValueA();291 $aInstance->a = 21;292 $aArray = ClassWithDiscriminatorMapMeta::toArray($aInstance);293 $this->assertArrayHasKey("value", $aArray);294 $this->assertEquals("a", $aArray["value"]);295 $this->assertArrayHasKey("a", $aArray);296 $this->assertEquals(21, $aArray["a"]);297 $this->assertArrayNotHasKey("b", $aArray);298 $bInstance = new ClassWithDiscriminatorValueB();299 $bInstance->b = 42;300 $bArray = ClassWithDiscriminatorMapMeta::toArray($bInstance);301 $this->assertArrayHasKey("value", $bArray);302 $this->assertEquals("b", $bArray["value"]);303 $this->assertArrayHasKey("b", $bArray);304 $this->assertEquals(42, $bArray["b"]);305 $this->assertArrayNotHasKey("a", $bArray);306 }307 public function testOverwriteClassWithPublicPropertyFromArray()308 {309 $instance = new ClassWithPublicProperty();310 $instance->property = "foobar";311 $this->assertEquals("foobar", $instance->property);312 ClassWithPublicPropertyMeta::fromArray(["property" => null], null, $instance);313 $this->assertNull($instance->property);314 }315 public function testOverwriteClassWithDatetimePropertyFromArray()316 {317 $now = new \DateTime();318 $instance = new ClassWithDatetimeProperty();319 $instance->datetime = $now;320 $this->assertEquals($now, $instance->datetime);321 ClassWithDatetimePropertyMeta::fromArray(["datetime" => null], null, $instance);322 $this->assertNull($instance->datetime);323 }324 public function testOverwriteClassWithArrayPropertyFromArray()325 {326 $instance = new ClassWithArrayProperty();327 $instance->array = ["foo" => ["bar" => "baz"]];328 $this->assertEquals(["foo" => ["bar" => "baz"]], $instance->array);329 ClassWithArrayPropertyMeta::fromArray(["array" => null], null, $instance);330 $this->assertNull($instance->array);331 }332 public function testClassWithRecursiveProperty()333 {334 $a = new ClassWithRecursiveProperty();335 $a->property = $a;336 $this->assertEquals(0, count(Stack::$objects));337 $this->assertEquals(["property" => null], ClassWithRecursivePropertyMeta::toArray($a));338 $this->assertEquals(0, count(Stack::$objects));339 $b = new ClassWithRecursiveProperty();340 $a->property = $b;341 $b->property = $a;342 $this->assertEquals(0, count(Stack::$objects));343 $this->assertEquals(["property" => ["property" => null]], ClassWithRecursivePropertyMeta::toArray($a));344 $this->assertEquals(0, count(Stack::$objects));345 try {346 $b->property = "wtf";347 $this->assertEquals(0, count(Stack::$objects));348 ClassWithRecursivePropertyMeta::toArray($a);349 $this->fail("An exception should be thrown.");350 } catch (\Exception $e) {351 $this->assertEquals(0, count(Stack::$objects));352 $this->assertEquals('You have to pass object of class Skrz\Meta\Fixtures\PHP\ClassWithRecursiveProperty.', $e->getMessage());353 }354 }355 public function testClassWithMorePropertiesFiltered()356 {357 $instance = new ClassWithMoreProperties();358 $instance->a = "foo1";359 $instance->b = "foo2";360 $instance->c = "foo3";361 $instance->d = "foo4";362 $instance->e = "foo5";363 $this->assertEquals(364 [365 "a" => "foo1",366 "b" => "foo2",367 "c" => "foo3",368 "d" => "foo4",369 "e" => "foo5",370 "f" => null,371 "g" => [],372 ],373 ClassWithMorePropertiesMeta::toArray($instance)374 );375 $this->assertEquals(376 [377 "a" => "foo1",378 ],379 ClassWithMorePropertiesMeta::toArray($instance, null, [380 "a" => true,381 ])382 );383 $this->assertEquals(384 [385 "b" => "foo2",386 "c" => "foo3",387 "d" => "foo4",388 ],389 ClassWithMorePropertiesMeta::toArray($instance, null, [390 "b" => true,391 "c" => true,392 "d" => true,393 ])394 );395 $instance2 = new ClassWithMoreProperties();396 $instance2->a = "foo6";397 $instance->f = $instance2;398 $this->assertEquals(399 [400 "e" => "foo5",401 "f" => [402 "a" => "foo6",403 "b" => null,404 ],405 ],406 ClassWithMorePropertiesMeta::toArray($instance, null, [407 "e" => true,408 "f" => [409 "a" => true,410 "b" => true,411 ],412 ])413 );414 $instance3 = new ClassWithMoreProperties();415 $instance3->a = "foo7";416 $instance->g = [$instance2, $instance3];417 $this->assertEquals(418 [419 "g" => [420 [421 "a" => "foo6",422 ],423 [424 "a" => "foo7",425 ]426 ],427 ],428 ClassWithMorePropertiesMeta::toArray($instance, null, [429 "g" => [430 "a" => true,431 ],432 ])433 );434 }435 public function testClassWithMorePropertiesFilteredByFieldsFromArray()436 {437 $instance = new ClassWithMoreProperties();438 $instance->a = "foo1";439 $instance->b = "foo2";440 $instance->c = "foo3";441 $instance->d = "foo4";442 $instance->e = "foo5";443 $this->assertEquals(444 [445 "a" => "foo1",446 "b" => "foo2",447 "c" => "foo3",448 "d" => "foo4",449 "e" => "foo5",450 "f" => null,451 "g" => [],452 ],453 ClassWithMorePropertiesMeta::toArray($instance)454 );455 $this->assertEquals(456 [457 "a" => "foo1",458 ],459 ClassWithMorePropertiesMeta::toArray($instance, null, Fields::fromArray([460 "a" => true,461 ]))462 );463 $this->assertEquals(464 [465 "b" => "foo2",466 "c" => "foo3",467 "d" => "foo4",468 ],469 ClassWithMorePropertiesMeta::toArray($instance, null, Fields::fromArray([470 "b" => true,471 "c" => true,472 "d" => true,473 ]))474 );475 $instance2 = new ClassWithMoreProperties();476 $instance2->a = "foo6";477 $instance->f = $instance2;478 $this->assertEquals(479 [480 "e" => "foo5",481 "f" => [482 "a" => "foo6",483 "b" => null,484 ],485 ],486 ClassWithMorePropertiesMeta::toArray($instance, null, Fields::fromArray([487 "e" => true,488 "f" => [489 "a" => true,490 "b" => true,491 ],492 ]))493 );494 $instance3 = new ClassWithMoreProperties();495 $instance3->a = "foo7";496 $instance->g = [$instance2, $instance3];497 $this->assertEquals(498 [499 "g" => [500 [501 "a" => "foo6",502 ],503 [504 "a" => "foo7",505 ]506 ],507 ],508 ClassWithMorePropertiesMeta::toArray($instance, null, Fields::fromArray([509 "g" => [510 "a" => true,511 ],512 ]))513 );514 }515 public function testClassWithMorePropertiesFilteredByFieldsFromString()516 {517 $instance = new ClassWithMoreProperties();518 $instance->a = "foo1";519 $instance->b = "foo2";520 $instance->c = "foo3";521 $instance->d = "foo4";522 $instance->e = "foo5";...

Full Screen

Full Screen

GrammarParserTest.php

Source:GrammarParserTest.php Github

copy

Full Screen

...73 public function provideTestItParsesTerminalRules(): iterable74 {75 yield 'double-quoted literal' => [76 'x = "x"',77 GrammarFactory::fromArray(['x' => new Literal('x', 'x', '"')]),78 ];79 yield 'double-quoted literal with escaped characters' => [80 'x = "x \" x"',81 GrammarFactory::fromArray(['x' => new Literal('x " x', 'x', '"')]),82 ];83 yield 'single-quoted literal' => [84 "x = 'x'",85 GrammarFactory::fromArray(['x' => new Literal('x', 'x', "'")]),86 ];87 yield 'single-quoted literal with escaped characters' => [88 "x = 'x \' x'",89 GrammarFactory::fromArray(['x' => new Literal("x \' x", 'x', "'")]),90 ];91 yield 'match' => [92 'x = /x/',93 GrammarFactory::fromArray(['x' => new RegExp('x', [], 'x')]),94 ];95 yield 'match with escaped delimiter' => [96 'x = /x \/ x/',97 GrammarFactory::fromArray(['x' => new RegExp('x \/ x', [], 'x')]),98 ];99 yield 'match with flags' => [100 'x = /x/i',101 GrammarFactory::fromArray(['x' => new RegExp('x', ['i'], 'x')]),102 ];103 yield 'match non-capturing groups' => [104 'x = /(?:x)(?!y)/',105 GrammarFactory::fromArray(['x' => new RegExp('(?:x)(?!y)', [], 'x')]),106 ];107 yield 'RegExp' => [108 'x = /x(y)/',109 GrammarFactory::fromArray(['x' => new CapturingRegExp('x(y)', [], 'x')]),110 ];111 yield 'Word literal' => [112 'x = `x`',113 GrammarFactory::fromArray(['x' => new Word('x', 'x')]),114 ];115 yield 'EOF' => [116 'x = EOF',117 GrammarFactory::fromArray(['x' => new EOF()]),118 ];119 yield 'Epsilon' => [120 'x = E',121 GrammarFactory::fromArray(['x' => new Epsilon()]),122 ];123 yield 'Fail' => [124 'x = FAIL',125 GrammarFactory::fromArray(['x' => new Fail()]),126 ];127 yield 'BackReference' => [128 'x = $x',129 GrammarFactory::fromArray(['x' => new BackReference('x')]),130 ];131 }132 /**133 * @dataProvider provideTestItParsesCombinators134 */135 public function testItParsesCombinators(string $syntax, Grammar $expected)136 {137 $grammar = $this->parseSyntax($syntax, OptimizationLevel::LEVEL_1);138 PegasusAssert::grammarEquals($expected, $grammar);139 }140 /**141 * @dataProvider provideTestItParsesCombinators142 */143 public function testItParsesCombinatorsWithOptimizedMeta(string $syntax, Grammar $expected)144 {145 $grammar = $this->parseSyntax($syntax, OptimizationLevel::LEVEL_1, true);146 PegasusAssert::grammarEquals($expected, $grammar);147 }148 public function provideTestItParsesCombinators(): iterable149 {150 yield 'Sequence of matches' => [151 'x = /x/ /y/ /z/',152 GrammarFactory::fromArray([153 'x' => new Sequence([154 new RegExp('x'),155 new RegExp('y'),156 new RegExp('z'),157 ]),158 ]),159 ];160 yield 'Choice of matches' => [161 'x = /x/ | /y/ | /z/',162 GrammarFactory::fromArray([163 'x' => new OneOf([164 new RegExp('x'),165 new RegExp('y'),166 new RegExp('z'),167 ]),168 ]),169 ];170 yield 'NodeAction of matches' => [171 'x = /x/ /y/ /z/ <= XYZ',172 GrammarFactory::fromArray([173 'x' => new NodeAction(new Sequence([174 new RegExp('x'),175 new RegExp('y'),176 new RegExp('z'),177 ]), 'XYZ'),178 ]),179 ];180 yield 'Choice with named sequence' => [181 'x = /x/ | /y/ <= Y | /z/',182 GrammarFactory::fromArray([183 'x' => new OneOf([184 new RegExp('x'),185 new NodeAction(new RegExp('y'), 'Y'),186 new RegExp('z'),187 ]),188 ]),189 ];190 }191 /**192 * @dataProvider provideTestItParsesDecorators193 */194 public function testItParsesDecorators(string $syntax, Grammar $expected)195 {196 $grammar = $this->parseSyntax($syntax);197 PegasusAssert::grammarEquals($expected, $grammar);198 }199 /**200 * @dataProvider provideTestItParsesDecorators201 */202 public function testItParsesDecoratorsWithOptimizedMeta(string $syntax, Grammar $expected)203 {204 $grammar = $this->parseSyntax($syntax, OptimizationLevel::NONE, true);205 PegasusAssert::grammarEquals($expected, $grammar);206 }207 public function provideTestItParsesDecorators(): iterable208 {209 yield 'Assert of a match' => [210 'x = &/x/',211 GrammarFactory::fromArray(['x' => new AssertExpr(new RegExp('x'))]),212 ];213 yield 'Not of a match' => [214 'x = !/x/',215 GrammarFactory::fromArray(['x' => new Not(new RegExp('x'))]),216 ];217 yield 'Skip of a match' => [218 'x = ~/x/',219 GrammarFactory::fromArray(['x' => new Ignore(new RegExp('x'))]),220 ];221 yield 'Token of a match' => [222 'x = %/x/',223 GrammarFactory::fromArray(['x' => new Token(new RegExp('x'))]),224 ];225 yield 'Labeled match' => [226 'x = a:/x/',227 GrammarFactory::fromArray(['x' => new Bind('a', new RegExp('x'))]),228 ];229 yield 'ZeroOrMore match' => [230 'x = /x/*',231 GrammarFactory::fromArray(['x' => new ZeroOrMore(new RegExp('x'))]),232 ];233 yield 'OneOrMore match' => [234 'x = /x/+',235 GrammarFactory::fromArray(['x' => new OneOrMore(new RegExp('x'))]),236 ];237 yield 'Optional match' => [238 'x = /x/?',239 GrammarFactory::fromArray(['x' => new Optional(new RegExp('x'))]),240 ];241 yield 'Exactly 2 match' => [242 'x = /x/{2}',243 GrammarFactory::fromArray(['x' => new Quantifier(new RegExp('x'), 2, 2)]),244 ];245 yield 'At least 2 match' => [246 'x = /x/{2,}',247 GrammarFactory::fromArray(['x' => new Quantifier(new RegExp('x'), 2)]),248 ];249 yield 'Between 2 and 4 match' => [250 'x = /x/{2,4}',251 GrammarFactory::fromArray(['x' => new Quantifier(new RegExp('x'), 2, 4)]),252 ];253 yield 'Cut operator' => [254 'x = "["^',255 GrammarFactory::fromArray(['x' => new Cut(new Literal('['))]),256 ];257 yield 'Cut quantifier' => [258 'x = "X"+^',259 GrammarFactory::fromArray(['x' => new Cut(new OneOrMore(new Literal('X')))]),260 ];261 }262 /**263 * @dataProvider provideTestDecoratorPrecedence264 */265 public function testDecoratorPrecedence(string $syntax, Grammar $expected)266 {267 $grammar = $this->parseSyntax($syntax);268 PegasusAssert::grammarEquals($expected, $grammar);269 }270 public function provideTestDecoratorPrecedence(): iterable271 {272 yield 'ignore and quantifier' => [273 'x = ~"foo"+',274 GrammarFactory::fromArray([275 'x' => new Ignore(new OneOrMore(new Literal('foo'))),276 ]),277 ];278 yield 'token and cut' => [279 'x = %"foo"^',280 GrammarFactory::fromArray([281 'x' => new Token(new Cut(new Literal('foo'))),282 ]),283 ];284 yield 'cut and quantifier' => [285 'x = "foo"+^',286 GrammarFactory::fromArray([287 'x' => new Cut(new OneOrMore(new Literal('foo'))),288 ]),289 ];290 yield 'ignore and token' => [291 'x = ~%"foo"',292 GrammarFactory::fromArray([293 'x' => new Ignore(new Token(new Literal('foo'))),294 ]),295 ];296 }297 /**298 * @dataProvider provideTestItParsesReferences299 */300 public function testItParsesReferences(string $syntax, Grammar $expected)301 {302 $grammar = $this->parseSyntax($syntax);303 PegasusAssert::grammarEquals($expected, $grammar);304 }305 /**306 * @dataProvider provideTestItParsesReferences307 */308 public function testItParsesReferencesWithOptimizedMeta(string $syntax, Grammar $expected)309 {310 $grammar = $this->parseSyntax($syntax, OptimizationLevel::NONE, true);311 PegasusAssert::grammarEquals($expected, $grammar);312 }313 public function provideTestItParsesReferences(): iterable314 {315 yield 'Reference' => [316 'x = y',317 GrammarFactory::fromArray(['x' => new Reference('y')]),318 ];319 yield 'Super' => [320 'x = super',321 GrammarFactory::fromArray(['x' => new Super('x')]),322 ];323 }324 public function testNameDirective()325 {326 $syntax = "@grammar Foo\nx = y";327 $expected = 'Foo';328 $grammar = $this->parseSyntax($syntax);329 Assert::assertSame($expected, $grammar->getName());330 $grammar = $this->parseSyntax($syntax, OptimizationLevel::NONE, true);331 Assert::assertSame($expected, $grammar->getName(), 'With optimized meta');332 }333 public function testStartDirective()334 {335 $syntax = "@start y\nx = y\ny = z";...

Full Screen

Full Screen

fromArray

Using AI Code Generation

copy

Full Screen

1$meta = new Meta();2$meta->fromArray(array(3));4$meta = new Meta();5$meta->fromArray(array(6));7$meta = new Meta();8$meta->fromArray(array(9));10$meta = new Meta();11$meta->fromArray(array(12));13$meta = new Meta();14$meta->fromArray(array(15));16$meta = new Meta();17$meta->fromArray(array(18));19$meta = new Meta();20$meta->fromArray(array(

Full Screen

Full Screen

fromArray

Using AI Code Generation

copy

Full Screen

1require_once 'Meta.php';2$meta = new Meta();3$meta->fromArray(array(4));5require_once 'Meta.php';6$meta = new Meta();7$meta->fromArray(array(8 'content-type' => 'text/html; charset=utf-8',9));10require_once 'Meta.php';11$meta = new Meta();12$meta->fromArray(array(13 'content-type' => 'text/html; charset=utf-8',

Full Screen

Full Screen

fromArray

Using AI Code Generation

copy

Full Screen

1$metas = array(2);3$meta = new Meta();4$meta->fromArray($metas);5echo $meta->render();6$metas = array(7);8$meta = new Meta();9$meta->fromArray($metas);10echo $meta->render();11$metas = array(12);13$meta = new Meta();14$meta->fromArray($metas);15echo $meta->render();16$metas = array(17);18$meta = new Meta();19$meta->fromArray($metas);20echo $meta->render();21$metas = array(22);23$meta = new Meta();24$meta->fromArray($metas);25echo $meta->render();26$metas = array(27);28$meta = new Meta();29$meta->fromArray($metas

Full Screen

Full Screen

fromArray

Using AI Code Generation

copy

Full Screen

1$meta = new Meta();2$meta->fromArray($array);3$meta->set('title', 'New Title');4$meta->set('description', 'New Description');5$meta->set('keywords', 'New Keywords');6$meta->set('robots', 'New Robots');7$meta->set('author', 'New Author');8$meta->set('generator', 'New Generator');9$meta->set('revisit-after', 'New Revisit After');10$meta->set('content-language', 'New Content Language');11$meta->set('content-type', 'New Content Type');12$meta->set('content-style-type', 'New Content Style Type');13$meta->set('pragma', 'New Pragma');14$meta->set('cache-control', 'New Cache Control');15$meta->set('expires', 'New Expires');16$meta->set('content-encoding', 'New Content Encoding');17$meta->set('content-disposition', 'New Content Disposition');18$meta->set('content-transfer-encoding', 'New Content Transfer Encoding');19$meta->set('content-location', 'New Content Location');20$meta->set('content-length', 'New Content Length');21$meta->set('content-base', 'New Content Base');22$meta->set('content-range', 'New Content Range');23$meta->set('content-version', 'New Content Version');24$meta->set('content-security-policy', 'New Content Security Policy');25$meta->set('content-security-policy-report-only', 'New Content Security Policy Report Only');26$meta->set('x-frame-options', 'New X Frame Options');27$meta->set('x-xss-protection', 'New X XSS Protection');28$meta->set('x-content-type-options', 'New X Content Type Options');29$meta->set('x-content-security-policy', 'New X Content Security Policy');30$meta->set('x-content-security-policy-report-only', 'New X Content Security Policy Report Only');31$meta->set('x-webkit-csp', 'New X Webkit CSP');32$meta->set('x-webkit-csp-report-only', 'New X Webkit CSP Report Only');33$meta->set('x-content-security-policy', 'New X Content Security Policy');34$meta->set('x-content-security-policy-report-only', 'New X Content Security Policy Report Only');35$meta->set('x-webkit-csp', 'New X Webkit CSP

Full Screen

Full Screen

fromArray

Using AI Code Generation

copy

Full Screen

1$meta = new Meta();2$meta->fromArray(array(3));4$meta->render();5$meta = new Meta();6$meta->fromArray(array(7));8$meta->render();

Full Screen

Full Screen

fromArray

Using AI Code Generation

copy

Full Screen

1$meta = new Meta();2$meta->fromArray($metaArray);3";4";5";6";7";8";9";10";11";12";13";14";15";16";17";18";19";

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Cucumber Common Library automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Trigger fromArray code on LambdaTest Cloud Grid

Execute automation tests with fromArray on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful