예제 #1
0
 public function testRunRepeatNoProviderNoAssert()
 {
     $maxMemory = 1;
     $timeUsed = 2;
     $expectedResult = array('\\Phprtest\\TestStub' => array('testStub' => array(1 => array('memoryUsage' => array('result' => $maxMemory), 'timeUsage' => array('result' => $timeUsed)), 2 => array('memoryUsage' => array('result' => $maxMemory), 'timeUsage' => array('result' => $timeUsed)), 3 => array('memoryUsage' => array('result' => $maxMemory), 'timeUsage' => array('result' => $timeUsed)))));
     $expectedResultChecked = array('\\Phprtest\\TestStub' => array('testStub' => array(1 => array('memoryUsage' => array('result' => $maxMemory, 'status' => 'ok'), 'timeUsage' => array('result' => $timeUsed, 'status' => 'ok')), 2 => array('memoryUsage' => array('result' => $maxMemory, 'status' => 'ok'), 'timeUsage' => array('result' => $timeUsed, 'status' => 'ok')), 3 => array('memoryUsage' => array('result' => $maxMemory, 'status' => 'ok'), 'timeUsage' => array('result' => $timeUsed, 'status' => 'ok')))));
     $expectedStatus = array('tests' => 0, 'softHits' => array(), 'hardHits' => array());
     $expectedStatusChecked = array('tests' => 3, 'softHits' => [], 'hardHits' => []);
     $expectedOutput = 'output';
     $printer = $this->getMock('\\Phprtest\\Printer\\PrinterInterface');
     $printer->expects($this->at(0))->method('render')->with($expectedResult, $expectedStatus)->will($this->returnValue($expectedOutput));
     $printer->expects($this->at(1))->method('render')->with($expectedResultChecked, $expectedStatusChecked)->will($this->returnValue($expectedOutput));
     $profiler = $this->getMock('\\Phprtest\\ProfilerInterface');
     $profiler->expects($this->any())->method('getMaxMemory')->will($this->returnValue($maxMemory));
     $profiler->expects($this->any())->method('getTimeUsed')->will($this->returnValue($timeUsed));
     $repeatAnnotation = $this->getMock('\\Phprtest\\Annotations\\RepeatAnnotation');
     $repeatAnnotation->expects($this->any())->method('getRepeatTimes')->will($this->returnValue(3));
     $annotations = $this->getMock('\\mindplay\\annotations\\AnnotationManager');
     $annotations->expects($this->at(0))->method('getMethodAnnotations')->with('Phprtest\\TestStub', 'testStub', '@provider')->will($this->returnValue([]));
     $annotations->expects($this->at(1))->method('getMethodAnnotations')->with('Phprtest\\TestStub', 'testStub', '@repeat')->will($this->returnValue([$repeatAnnotation]));
     $annotations->expects($this->at(2))->method('getMethodAnnotations')->with('Phprtest\\TestStub', 'testStub', '@assert')->will($this->returnValue([]));
     $this->instance->setAnnotations($annotations);
     $this->instance->setProfiler($profiler);
     $this->instance->setPrinter($printer);
     $this->instance->run('\\Phprtest\\TestStub');
     $this->assertEquals($expectedOutput, $this->instance->processResults(), "", 0.1, 5);
     $this->instance->checkLimits();
     $this->assertEquals($expectedOutput, $this->instance->processResults(), "", 0.1, 5);
     $this->assertFalse($this->instance->isFailure());
 }
예제 #2
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln(Phprtest::versionString() . PHP_EOL . str_repeat('-', strlen(Phprtest::versionString()) + 5) . PHP_EOL);
     $tests = $this->loadTests($input->getArgument('suite'));
     if ($input->getOption('etalon-test')) {
         array_unshift($tests, 'Phprtest\\EtalonTest');
     }
     $phprtest = new Phprtest();
     foreach ($tests as $test) {
         $phprtest->run($test);
     }
     if ($input->getOption('no-checks')) {
         $output->writeln("<fg=white;bg=yellow>  All assertions are skipped (--no-checks flag)  </fg=white;bg=yellow>\n");
     } else {
         $phprtest->checkLimits();
     }
     $output->write($phprtest->processResults());
     if ($phprtest->isFailure()) {
         $output->writeln("\n<fg=white;bg=red>\n TEST FAILED \n</fg=white;bg=red>");
         exit(1);
     }
 }