/** * @param Database $db * @param string $propertyType * @param string $searchBy * @return Collection|CodepointAssigned[] * @throws UnexpectedValueException */ private function resolveCodepoints(Database $db, $propertyType, $searchBy) { switch ($propertyType) { case self::PROPERTY_BLOCK: $block = Block::fromValue($searchBy); return $db->getByBlock($block); case self::PROPERTY_CATEGORY: $category = GeneralCategory::fromValue($searchBy); return $db->getByCategory($category); case self::PROPERTY_SCRIPT: $script = Script::fromValue($searchBy); return $db->getByScript($script); } throw new UnexpectedValueException(); }
/** * @test */ public function it_displays_characters_residing_in_a_supplied_script() { $repository = new InMemoryRepository(); $codepoint = Codepoint::fromInt(97); $script = Script::fromValue(Script::LATIN); $character = $this->buildCharacterWithCodepoint($codepoint, null, null, $script); $characters = Collection::fromArray([$character]); $repository->addMany($characters); $this->container['repository.test'] = $repository; $this->commandTester->execute(['command' => PropertiesCommand::COMMAND_NAME, '--from' => 'test', 'property-type' => PropertiesCommand::PROPERTY_SCRIPT, 'value' => $script->getValue()]); $output = $this->commandTester->getDisplay(); $statusCode = $this->commandTester->getStatusCode(); ha::assertThat('output', $output, hm::containsString('U+61:')); ha::assertThat('status code', $statusCode, hm::is(hm::identicalTo(0))); }
/** * @test */ public function it_can_provide_all_codepoints_residing_in_a_specific_script() { $script = Script::fromValue(Script::COMMON); $codepoints = $this->repository->getCodepointsByScript($script); ha::assertThat('count', count($codepoints), hm::is(hm::equalTo(1))); }
public function it_exposes_codepoints_for_a_requested_script(Character $c1, Character $c2, Character $c3) { $this->givenCharacterHasCodepointWithValue($c1, 1); $this->givenCharacterHasCodepointWithValue($c2, 2); $this->givenCharacterHasCodepointWithValue($c3, 3); $this->givenCharacterResidesInScript($c1, Script::fromValue(Script::SAMARITAN)); $this->givenCharacterResidesInScript($c2, Script::fromValue(Script::SAMARITAN)); $this->givenCharacterResidesInScript($c3, Script::fromValue(Script::COMMON)); $this->givenTheRepositoryHasCharacters([$c1, $c2, $c3]); $this->getCodepointsByScript(Script::fromValue(Script::SAMARITAN))->shouldIterateLike([Range::between(Codepoint::fromInt(1), Codepoint::fromInt(2))]); }
public function it_delegates_getCodepointsByScript_calls($repository) { $ranges = Codepoint\Range\Collection::fromArray([]); $script = Script::fromValue(Script::SAMARITAN); $repository->getCodepointsByScript($script)->willReturn($ranges); $this->getCodepointsByScript($script)->shouldReturn($ranges); }
public function it_should_always_throw_a_ScriptNotFoundException_when_searching_by_script() { $this->shouldThrow(ScriptNotFoundException::class)->during('getCodepointsByScript', [Script::fromValue(Script::COMMON)]); }
public function it_exposes_codepoints_for_a_requested_script($propertiesDirectory, PropertyFile $file) { $propertiesDirectory->getFileForProperty(Property::ofType(Property::SCRIPT))->willReturn($file); $file->read()->willReturn([Script::SAMARITAN => 's:{}']); $this->serializer->unserialize('s:{}')->willReturn($r = [Codepoint\Range::between(Codepoint::fromInt(0), Codepoint::fromInt(1))]); $this->getCodepointsByScript(Script::fromValue(Script::SAMARITAN))->shouldBeLike(Collection::fromArray($r)); }
public function it_can_provide_all_codepoint_assigned_entities_in_a_given_script() { $characters = Character\Collection::fromArray([]); $codepoint = Codepoint::fromInt(1); $ranges = Codepoint\Range\Collection::fromArray([$codepoint]); $script = Script::fromValue(Script::COMMON); $this->repository->getCodepointsByScript($script)->willReturn($ranges); $this->repository->getByCodepoints($ranges->expand())->willReturn($characters); $this->getByScript($script)->shouldReturn($characters); }