예제 #1
0
 public function testStopwatch()
 {
     $stopwatch = new Stopwatch('event_name');
     $this->assertSame('event_name', $stopwatch->getName());
     $start_event = $stopwatch->start('name', 'group');
     $this->assertInstanceOf(Event::class, $start_event);
     $this->assertSame('name', $start_event->getName());
     $this->assertSame('group', $start_event->getGroup());
     $reflection = ReflectionClass::from($stopwatch);
     $events = $reflection->getPropertyValue('events');
     $this->assertSame($events, $stopwatch->getEvents());
     $this->assertArrayHasKey('name', $events);
     $this->assertSame($start_event, $events['name']);
     $this->assertSame($start_event, $stopwatch->getEvent('name'));
     $this->assertTrue($start_event->hasStartedLaps());
     $this->assertCount(0, $start_event->getStoppedLaps());
     $lap_event = $stopwatch->lap('name');
     $this->assertInstanceOf(Event::class, $lap_event);
     $this->assertSame($start_event, $lap_event);
     $this->assertTrue($start_event->hasStartedLaps());
     $this->assertCount(1, $start_event->getStoppedLaps());
     $stop_event = $stopwatch->stop('name');
     $this->assertInstanceOf(Event::class, $stop_event);
     $this->assertSame($start_event, $stop_event);
     $this->assertFalse($start_event->hasStartedLaps());
     $this->assertCount(2, $start_event->getStoppedLaps());
 }
 public function testGetPropertyValue()
 {
     $class = new TestClass();
     $this->assertNull($class->getTestProperty());
     $this->assertNull(ReflectionClass::from($class)->getPropertyValue('test_property'));
     $class->setTestProperty('foo');
     $this->assertSame('foo', ReflectionClass::from($class)->getPropertyValue('test_property'));
 }
예제 #3
0
 public function testTokenIteratorDoSomethingMagic()
 {
     $tokens = $this->prepareTestTokens();
     $iterator = new TokenIterator($tokens);
     $reflection = ReflectionClass::from($iterator);
     // Find expected tokens in both right
     $this->assertSame([$tokens[0], $tokens[1], $tokens[2]], $reflection->invokeMethod('doSomethingMagic', [['TOKEN_A', 'B', 'TOKEN_C'], true, false, false, false]));
     $iterator->rewind();
     // Find expected tokens in both left
     $iterator->seek(3);
     $this->assertSame([$tokens[0], $tokens[1], $tokens[2]], $reflection->invokeMethod('doSomethingMagic', [['TOKEN_A', 'B', 'TOKEN_C'], true, false, false, true]));
     // Find not expected tokens in both right
     $iterator->rewind();
     $this->assertSame([$tokens[0], $tokens[1], $tokens[2]], $reflection->invokeMethod('doSomethingMagic', [['TOKEN_D', 'E'], false, false, false, false]));
     // Find not expected tokens in both left
     $iterator->seek(4);
     $this->assertSame([$tokens[2], $tokens[3]], $reflection->invokeMethod('doSomethingMagic', [['TOKEN_A', 'B'], false, false, false, true]));
     $iterator->next();
     $this->assertSame([$tokens[2]], $reflection->invokeMethod('doSomethingMagic', [['TOKEN_A', 'B'], false, false, false, true]));
     // Find one expected token in both right
     $iterator->rewind();
     $this->assertSame($tokens[0], $reflection->invokeMethod('doSomethingMagic', [['TOKEN_A', 'B', 'TOKEN_C'], true, true, false, false]));
     // Find one expected token in both left
     $iterator->seek(3);
     $this->assertSame($tokens[2], $reflection->invokeMethod('doSomethingMagic', [['TOKEN_A', 'B', 'TOKEN_C'], true, true, false, true]));
     // Find one not expected token in both right
     $iterator->rewind();
     $this->assertSame($tokens[2], $reflection->invokeMethod('doSomethingMagic', [['TOKEN_A', 'B'], false, true, false, false]));
     // Find one not expected token in both left
     $iterator->seek(5);
     $this->assertSame($tokens[4], $reflection->invokeMethod('doSomethingMagic', [['B', 'TOKEN_C'], false, true, false, true]));
     $iterator->prev();
     $this->assertSame($tokens[0], $reflection->invokeMethod('doSomethingMagic', [['B', 'TOKEN_C'], false, true, false, true]));
     // Join expected tokens in both right
     $iterator->rewind();
     $this->assertSame('ABC', $reflection->invokeMethod('doSomethingMagic', [['TOKEN_A', 'B', 'TOKEN_C'], true, false, true, false]));
     // Join expected tokens in both left
     $iterator->seek(3);
     $this->assertSame('ABC', $reflection->invokeMethod('doSomethingMagic', [['TOKEN_A', 'B', 'TOKEN_C'], true, false, true, true]));
     // Join not expected tokens in both right
     $iterator->rewind();
     $this->assertSame('ABC', $reflection->invokeMethod('doSomethingMagic', [['TOKEN_D', 'E'], false, false, true, false]));
     // Join not expected tokens in both left
     $iterator->seek(4);
     $this->assertSame('CD', $reflection->invokeMethod('doSomethingMagic', [['TOKEN_A', 'B'], false, false, true, true]));
     $iterator->next();
     $this->assertSame('C', $reflection->invokeMethod('doSomethingMagic', [['TOKEN_A', 'B'], false, false, true, true]));
     // Join one expected token in both right
     $iterator->rewind();
     $this->assertSame('A', $reflection->invokeMethod('doSomethingMagic', [['TOKEN_A', 'B', 'TOKEN_C'], true, true, true, false]));
     // Join one expected token in both left
     $iterator->seek(3);
     $this->assertSame('C', $reflection->invokeMethod('doSomethingMagic', [['TOKEN_A', 'B', 'TOKEN_C'], true, true, true, true]));
 }
예제 #4
0
 public function testManager()
 {
     $manager = new Manager();
     $this->assertFalse($manager->stopwatchExists('foo'));
     $reflection = ReflectionClass::from($manager);
     $reflection->setPropertyValue('stopwatches', ['foo' => true]);
     $this->assertTrue($manager->stopwatchExists('foo'));
     $this->assertSame(['foo' => true], $manager->getStopwatches());
     $manager->removeStopwatch('foo');
     $this->assertFalse($manager->stopwatchExists('foo'));
     $stopwatch = new Stopwatch();
     $manager->addStopwatch($stopwatch);
     $this->assertTrue($manager->stopwatchExists(null));
     $this->assertSame($stopwatch, $manager->getStopwatch(null));
 }
 public function testOptions()
 {
     $extension = new BarDumpExtension(['foo']);
     $this->assertSame(['foo'], ReflectionClass::from($extension)->getPropertyValue('options'));
 }