Unit tests does not use Group Object #2617

Closed
sergeyklay opened this Issue Dec 8, 2015 · 0 comments

Comments

Projects
None yet
2 participants
@sergeyklay
Member

sergeyklay commented Dec 8, 2015

codeception.yml

actor: Tester
paths:
    tests: tests
    log: tests/_output
    data: tests/_data
    support: tests/_support
    envs: tests/_envs
settings:
    bootstrap: _bootstrap.php
    memory_limit: 1024M
extensions:
    enabled:
        - Codeception\Extension\RunFailed
        - Group\Abc

tests/_support/Group/Abc.php

<?php
namespace Group;

use Codeception\Event\TestEvent;
use Codeception\Platform\Group;

class Abc extends Group
{
    public static $group = 'abc';

    public function _before(TestEvent $e)
    {
        $this->writeln('we are here');
        $e->getTest()->markTestSkipped('WE SKIP TEST');
    }

    public function _after(TestEvent $e)
    {
    }
}

tests/unit/SomeTest.php

<?php

use Codeception\TestCase\Test;

/**
 * @group abc
 */
class SomeTest extends Test
{
    /**
     * @var UnitTester
     */
    protected $tester;

    protected function _before()
    {
       // $this->getScenario()->group(\Group\Abc::$group); // abc
    }

    protected function _after()
    {
    }

    public function testFoo()
    {
        $this->assertTrue(false);
    }
}
$ vendor/bin/codecept run -g abc
Codeception PHP Testing Framework v2.1.4
Powered by PHPUnit 4.8.19 by Sebastian Bergmann and contributors.
[Groups] abc 

Unit Tests (126) --------------------------------------------------------------
Test foo (SomeTest::testFoo)                                               Fail
-------------------------------------------------------------------------------


Time: 1.43 seconds, Memory: 17.25Mb

There was 1 failure:

---------
1) Test foo (SomeTest::testFoo)
Failed asserting that false is true.
#1  <...>/tests/unit/SomeTest.php:26
#2  SomeTest->testFoo

FAILURES!
Tests: 1, Assertions: 1, Failures: 1.

This can be fixed by changing Codeception\SuiteManager from

if (!empty($groups) && $test instanceof TestCase\Interfaces\ScenarioDriven && null !== $test->getScenario()) {
    $test->getScenario()->group($groups);
}

to

if (!empty($groups) && null !== $test->getScenario()) {
    $test->getScenario()->group($groups);
}

But in this case I get an PHPUnit_Framework_SkippedTestError exception:

Trying to test foo (SomeTest::testFoo)... we are here



  [PHPUnit_Framework_SkippedTestError]  
  WE SKIP TEST                          


...
<backtrace here>
...
  1. This is bug?
  2. How to correctly skip grouped tests (e.g. in case of non-compliance to dependencies)

Thanks

@DavertMik DavertMik added the BUG label Dec 16, 2015

DavertMik added a commit that referenced this issue Dec 19, 2015

DavertMik added a commit that referenced this issue Dec 19, 2015

@DavertMik DavertMik referenced this issue Dec 19, 2015

Merged

Groupobjfix #2643

@DavertMik DavertMik closed this in #2643 Dec 19, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment