예제 #1
0
파일: Util.php 프로젝트: aaron-em/matura
 public static function gensuite($config = array(), $current_depth = 1)
 {
     $config = array_merge(array('befores' => 0, 'before_alls' => 0, 'afters' => 0, 'after_alls' => 0, 'tests' => 1, 'depth' => 0, 'describes' => array('L', 'R'), 'callbacks' => array('it' => function ($ctx) {
         expect(true)->to->eql(true);
     }, 'before' => function ($ctx) {
         $ctx->value = 3;
     }, 'before_all' => function ($ctx) {
         $ctx->value = 5;
     }, 'after' => function ($ctx) {
         $ctx->value = 7;
     }, 'after_all' => function ($ctx) {
         $ctx->value = 11;
     })), $config);
     if ($config['depth'] == 0) {
         return;
     }
     foreach ($config['describes'] as $side) {
         describe("Level {$side}{$current_depth}", function ($ctx) use($config, $current_depth) {
             for ($i = 1; $i <= $config['tests']; $i++) {
                 it("nested {$i}", $config['callbacks']['it']);
             }
             for ($i = 1; $i <= $config['befores']; $i++) {
                 before($config['callbacks']['before']);
             }
             for ($i = 1; $i <= $config['before_alls']; $i++) {
                 before_all($config['callbacks']['before_all']);
             }
             for ($i = 1; $i <= $config['after_alls']; $i++) {
                 after_all($config['callbacks']['after_all']);
             }
             for ($i = 1; $i <= $config['afters']; $i++) {
                 after($config['callbacks']['after']);
             }
             $config['depth']--;
             Util::gensuite($config, $current_depth + 1);
         });
     }
 }
예제 #2
0
             expect($result->totalTests())->to->eql(2);
         });
     });
 });
 describe('Error Capture and Reporting', function ($ctx) {
     before(function ($ctx) {
         $ctx->spy = $spy = Mockery::mock()->shouldIgnoreMissing();
         $ctx->listener = Mockery::mock('Matura\\Events\\Listener')->shouldIgnoreMissing();
         $ctx->suite = suite('Fixture', function ($inner_ctx) use($spy, $ctx) {
             $ctx->before_all = before_all(array($spy, 'before_all'));
             $ctx->after_all = after_all(array($spy, 'after_all'));
             $ctx->after = after(array($spy, 'after'));
             $ctx->before = before(array($spy, 'before'));
             $ctx->describe = describe('Inner', function ($inner_ctx) use($spy, $ctx) {
                 $ctx->inner_before_all = before_all(array($spy, 'inner_before_all'));
                 $ctx->inner_after_all = after_all(array($spy, 'inner_after_all'));
                 $ctx->inner_after = after(array($spy, 'inner_after'));
                 $ctx->inner_before = before(array($spy, 'inner_before'));
                 $ctx->test = it('should have a test case', array($spy, 'it'));
             });
         });
         $ctx->suite_runner = new SuiteRunner($ctx->suite, new ResultSet());
         $ctx->suite_runner->addListener($ctx->listener);
     });
     describe('At the Suite Level', function ($ctx) {
         it('should capture before_all errors', function ($ctx) {
             $ctx->spy->shouldReceive('before_all')->once()->andThrow('\\Exception');
             $ctx->suite_runner->run();
             $failures = $ctx->suite_runner->getResultSet()->getFailures();
             expect($failures)->to->have->length(1);
             expect($failures[0]->getBlock())->to->be($ctx->suite);