<commit_before><?php
declare(strict_types=1);
namespace Viserio\Component\Events\Tests;

use PHPUnit\Framework\TestCase;
use Viserio\Component\Contracts\Events\EventManager;
use Viserio\Component\Events\ListenerPattern;

class ListenerPatternTest extends TestCase
{
    /**
     * @dataProvider providePatternsAndMatches
     *
     * @param mixed $eventPattern
     * @param array $expectedMatches
     * @param array $expectedMisses
     */
    public function testPatternMatching($eventPattern, array $expectedMatches, array $expectedMisses)
    {
        $pattern = new ListenerPattern($eventPattern, null);

        foreach ($expectedMatches as $eventName) {
            self::assertTrue(
                $pattern->test($eventName),
                sprintf('Pattern "%s" should match event "%s"', $eventPattern, $eventName)
            );
        }

        foreach ($expectedMisses as $eventName) {
            self::assertFalse(
                $pattern->test($eventName),
                sprintf('Pattern "%s" should not match event "%s"', $eventPattern, $eventName)
            );
        }
    }

    public function providePatternsAndMatches()
    {
        return [
            [
                '*',
                ['core', 'api', 'v2'],
                ['', 'core.request'],
            ],
            [
                '*.exception',
                ['core.exception', 'api.exception'],<commit_msg>Issue 476 (#477)<commit_after><?php
declare(strict_types=1);
namespace Viserio\Component\Events\Tests;

use PHPUnit\Framework\TestCase;
use Viserio\Component\Contracts\Events\EventManager;
use Viserio\Component\Events\ListenerPattern;

class ListenerPatternTest extends TestCase
{
    /**
     * @dataProvider providePatternsAndMatches
     *
     * @param mixed $eventPattern
     * @param array $expectedMatches
     * @param array $expectedMisses
     */
    public function testPatternMatching($eventPattern, array $expectedMatches, array $expectedMisses)
    {
        $pattern = new ListenerPattern($eventPattern, null);

        foreach ($expectedMatches as $eventName) {
            self::assertTrue(
                $pattern->test($eventName),
                sprintf('Pattern [%s] should match event [%s]', $eventPattern, $eventName)
            );
        }

        foreach ($expectedMisses as $eventName) {
            self::assertFalse(
                $pattern->test($eventName),
                sprintf('Pattern [%s] should not match event [%s]', $eventPattern, $eventName)
            );
        }
    }

    public function providePatternsAndMatches()
    {
        return [
            [
                '*',
                ['core', 'api', 'v2'],
                ['', 'core.request'],
            ],
            [
                '*.exception',
                ['core.exception', 'api.exception'],
{'fraction_non_alphanumeric': 0.12115860120098905, 'fraction_numerical': 0.0035323207347227126, 'mean_word_length': 2.1086717892425906, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '7530944', 'n_tokens_mistral': 772, 'n_tokens_neox': 745, 'n_words': 153}