예제 #1
0
 public function testSimple()
 {
     $this->expectOutputString("onFinish\nonFinish");
     $item = new Item();
     $item->attach($this);
     $manager = new Manager(new Item('N'));
     $this->assertSame('N', $manager->getPrototype()->getTitle());
     $this->assertSame($manager, $manager->setPrototype($item));
     $this->assertSame($item, $manager->getPrototype());
     $this->assertInstanceOf(\SplQueue::class, $manager->getIterator());
     $this->assertNull($manager->top());
     foreach ($manager as $item) {
         $this->fail('Should be empty iteration now: ' . gettype($item));
     }
     $newItem = $manager->create('1');
     $this->assertInstanceOf(Item::class, $newItem);
     $this->assertSame('1', $newItem->getTitle());
     $this->assertNotSame($item, $newItem);
     $this->assertSame($newItem, $manager->start());
     $this->assertInstanceOf(StateRunning::class, $newItem->getState());
     $this->assertInstanceOf(StatePaused::class, $manager->pause()->getState());
     $this->assertSame($newItem, $manager->top());
     $this->assertInstanceOf(StateRunning::class, $manager->resume()->getState());
     $newItem->stop();
     $this->assertNull($manager->discard());
     echo "\n";
     $this->assertNotSame($newItem, $newItem2 = $manager->namedStart('2'));
     $this->assertCount(1, $manager);
     $this->assertSame('2', $newItem2->getTitle());
     $this->assertSame($newItem2, $manager->stop());
     $this->assertCount(2, $manager);
     $item->detach($this);
     $this->assertSame('3', $manager->start()->setTitle('3')->setHandled(true)->stop()->getTitle());
     $this->assertCount(2, $manager);
 }
예제 #2
0
 public function testTag()
 {
     $manager = new Manager();
     $tag = new TaggingObserver('SQL');
     $this->assertSame('SQL', $tag->getTag());
     $manager->getPrototype()->attach($tag);
     $manager->namedStart('foo');
     $item = $manager->stop();
     $this->assertSame('foo', $item->getTitle());
     $this->assertSame('SQL', $item->getStatistic(TaggingObserver::class, TaggingObserver::FILED_TAG));
 }