Ejemplo n.º 1
0
 /**
  * {@inheritDoc}
  */
 public function addMany(Collection $characters)
 {
     $function = __FUNCTION__;
     $characters->traverseWith(function (CodepointAssigned $c) use($function) {
         $this->logMethodCall($function, [(string) $c->getCodepoint()]);
     });
     $this->delegate->addMany($characters);
     $this->notify();
 }
Ejemplo n.º 2
0
 private function givenTheRepositoryHasCharacters(array $items)
 {
     $unwrapped = array_map(function (Collaborator $item) {
         return $item->getWrappedObject();
     }, $items);
     $this->addMany(Character\Collection::fromArray($unwrapped));
 }
Ejemplo n.º 3
0
 protected function setUp()
 {
     $this->repository = new InMemoryRepository();
     $character = $this->buildCharacterWithCodepoint(Codepoint::fromInt(0));
     $characters = Collection::fromArray([$character]);
     $this->repository->addMany($characters);
 }
Ejemplo n.º 4
0
 public function it_writes_aggregations_after_all_characters_have_been_added($propertiesDirectory, Property $property, AggregatorRelay $aggregator, $aggregators, Character $character)
 {
     $aggregator->getAllRanges()->willReturn(['foo' => Collection::fromArray(['x'])]);
     $aggregators->getIterator()->will(function () use($property, $aggregator) {
         (yield $property->getWrappedObject() => $aggregator->getWrappedObject());
     });
     $aggregators->addCharacters(Argument::any())->willReturn(null);
     $this->serializer->serialize(Argument::any())->willReturn('serialized');
     $propertiesDirectory->writeProperty($property, ['foo' => 'serialized'])->shouldBeCalled();
     $this->givenCharacterHasCodepointWithValue($character, 1);
     $this->addMany(Character\Collection::fromArray([$character->getWrappedObject()]));
 }
Ejemplo n.º 5
0
 /**
  * @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)));
 }
Ejemplo n.º 6
0
 /**
  * @test
  */
 public function it_displays_details_for_resolved_characters()
 {
     $repository = new InMemoryRepository();
     $codepoint = Codepoint::fromInt(163);
     $character = $this->buildCharacterWithCodepoint($codepoint);
     $characters = Collection::fromArray([$character]);
     $repository->addMany($characters);
     $this->container['repository.test'] = $repository;
     $this->commandTester->execute(['command' => SearchCommand::COMMAND_NAME, '--from' => 'test', '--enc' => SearchCommand::ENCODING_DECIMAL, 'codepoint' => $codepoint->getValue()]);
     $output = $this->commandTester->getDisplay();
     $statusCode = $this->commandTester->getStatusCode();
     ha::assertThat('output', $output, hm::containsString('Character Found'));
     ha::assertThat('output', $output, hm::containsString('Export: UCD\\Unicode\\Character'));
     ha::assertThat('output', $output, hm::containsString('UTF-8: £'));
     ha::assertThat('status code', $statusCode, hm::is(hm::identicalTo(0)));
 }
 /**
  * @test
  */
 public function it_transfers_characters_from_one_repository_to_another()
 {
     $codepoint = Codepoint::fromInt(1);
     $character = $this->buildCharacterWithCodepoint($codepoint);
     $characters = Collection::fromArray([$character]);
     $source = new InMemoryRepository();
     $source->addMany($characters);
     $destination = new InMemoryRepository();
     $this->container['repository.test-source'] = $source;
     $this->container['repository.test-destination'] = $destination;
     ha::assertThat(count($source), hm::is(hm::identicalTo(1)));
     ha::assertThat(count($destination), hm::is(hm::identicalTo(0)));
     $this->commandTester->execute(['command' => RepositoryTransferCommand::COMMAND_NAME, 'from' => 'test-source', 'to' => 'test-destination']);
     ha::assertThat(count($source), hm::is(hm::identicalTo(1)));
     ha::assertThat(count($destination), hm::is(hm::identicalTo(1)));
     $output = $this->commandTester->getDisplay();
     $statusCode = $this->commandTester->getStatusCode();
     ha::assertThat('output', $output, hm::containsString('Database Generated'));
     ha::assertThat('status code', $statusCode, hm::is(hm::identicalTo(0)));
 }
Ejemplo n.º 8
0
 /**
  * @test
  */
 public function it_can_be_added_to_if_writable()
 {
     if (!$this->repository instanceof WritableRepository) {
         $this->markTestSkipped('Repository is not writable');
     }
     $codepoint = Codepoint::fromInt(1);
     $addCharacter = $this->buildCharacterWithCodepoint($codepoint);
     $addCharacters = Character\Collection::fromArray([$addCharacter]);
     $this->repository->addMany($addCharacters);
     $character = $this->repository->getByCodepoint($codepoint);
     ha::assertThat('character', $character, hm::is(hm::equalTo($addCharacter)));
     ha::assertThat('count', count($this->repository), hm::is(hm::equalTo(2)));
 }
Ejemplo n.º 9
0
 /**
  * {@inheritDoc}
  */
 public function getAll()
 {
     return Collection::fromArray($this->characters);
 }
Ejemplo n.º 10
0
 /**
  * {@inheritDoc}
  */
 public function getAll()
 {
     return CharacterCollection::fromArray([]);
 }
Ejemplo n.º 11
0
 public function it_delegates_getAll_calls($repository)
 {
     $collection = Character\Collection::fromArray([]);
     $repository->getAll()->willReturn($collection);
     $this->getAll()->shouldReturn($collection);
 }
Ejemplo n.º 12
0
 private function givenTheRepositoryContains(array $items)
 {
     $unwrapped = array_map(function (Collaborator $c) {
         return $c->getWrappedObject();
     }, $items);
     $this->repository->getAll()->willReturn(Collection::fromArray($unwrapped));
 }
 public function it_notifies_observers_when_characters_are_added(\SplObserver $observer, Character $character)
 {
     $observer->update($this)->shouldBeCalled();
     $this->attach($observer);
     $this->addMany(Character\Collection::fromArray([$character->getWrappedObject()]));
 }