<commit_before><?php

declare(strict_types=1);

namespace Codeception\Test\Loader;

use Codeception\Lib\Parser;
use Codeception\Test\Cest as CestFormat;
use Codeception\Test\DataProvider;
use ReflectionClass;

use function get_class_methods;

class Cest implements LoaderInterface
{
    /**
     * @var CestFormat[]
     */
    protected array $tests = [];

    /**
     * @return CestFormat[]
     */
    public function getTests(): array
    {
        return $this->tests;
    }

    public function getPattern(): string
    {
        return '~Cest\.php$~';
    }

    public function loadTests(string $filename): void
    {
        Parser::load($filename);
        $testClasses = Parser::getClassesFromFile($filename);

        foreach ($testClasses as $testClass) {
            if (!str_ends_with($testClass, 'Cest')) {
                continue;
            }
            if (!(new ReflectionClass($testClass))->isInstantiable()) {
                continue;
            }
            $unit = new $testClass();

            $methods = get_class_methods($testClass);
            foreach ($methods as $method) {
                if (str_starts_with($method, '_')) {
                    continue;
                }

                $examples = DataProvider::getDataForMethod(new \ReflectionMethod($testClass, $method));

                if ($examples === null) {
                    $this->tests[] = new CestFormat($unit, $method, $filename);
                    continue;
                }

                foreach ($examples as $i => $example) {
                    $test = new CestFormat($unit, $method, $filename);
                    $test->getMetadata()->setCurrent(['example' => $example]);
                    $test->getMetadata()->setIndex($i);
                    $this->tests[] = $test;
                }
            }
        }
    }
}
<commit_msg>Fix dataProvider work for abstract Cest class (#6558)<commit_after><?php

declare(strict_types=1);

namespace Codeception\Test\Loader;

use Codeception\Lib\Parser;
use Codeception\Test\Cest as CestFormat;
use Codeception\Test\DataProvider;
use ReflectionClass;

use function get_class_methods;

class Cest implements LoaderInterface
{
    /**
     * @var CestFormat[]
     */
    protected array $tests = [];

    /**
     * @return CestFormat[]
     */
    public function getTests(): array
    {
        return $this->tests;
    }

    public function getPattern(): string
    {
        return '~Cest\.php$~';
    }

    public function loadTests(string $filename): void
    {
        Parser::load($filename);
        $testClasses = Parser::getClassesFromFile($filename);

        foreach ($testClasses as $testClass) {
            if (!str_ends_with($testClass, 'Cest')) {
                continue;
            }
            if (!(new ReflectionClass($testClass))->isInstantiable()) {
                continue;
            }
            $unit = new $testClass();

            $methods = get_class_methods($testClass);
            foreach ($methods as $method) {
                if (str_starts_with($method, '_')) {
                    continue;
                }

                $examples = DataProvider::getDataForMethod(
                    new \ReflectionMethod($testClass, $method),
                    new \ReflectionClass($testClass)
                );

                if ($examples === null) {
                    $this->tests[] = new CestFormat($unit, $method, $filename);
                    continue;
                }

                foreach ($examples as $i => $example) {
                    $test = new CestFormat($unit, $method, $filename);
                    $test->getMetadata()->setCurrent(['example' => $example]);
                    $test->getMetadata()->setIndex($i);
                    $this->tests[] = $test;
                }
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.12831168831168832, 'fraction_numerical': 0.0015584415584415584, 'mean_word_length': 1.7215547703180212, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '112509', 'n_tokens_mistral': 1056, 'n_tokens_neox': 994, 'n_words': 210}