<commit_before><?php

/**
 * This file is part of CodeIgniter 4 framework.
 *
 * (c) CodeIgniter Foundation <<EMAIL>>
 *
 * For the full copyright and license information, please view
 * the LICENSE file that was distributed with this source code.
 */

namespace CodeIgniter\Test;

use CodeIgniter\CLI\CLI;
use CodeIgniter\Events\Events;
use CodeIgniter\HTTP\Response;
use CodeIgniter\Test\Filters\CITestStreamFilter;
use Config\App;

/**
 * @internal
 */
final class TestCaseTest extends CIUnitTestCase
{
    /**
     * @var bool|resource
     */
    private $stream_filter;

    public function testGetPrivatePropertyWithObject()
    {
        $obj    = new __TestForReflectionHelper();
        $actual = $this->getPrivateProperty($obj, 'private');
        $this->assertSame('secret', $actual);
    }

    public function testLogging()
    {
        log_message('error', 'Some variable did not contain a value.');
        $this->assertLogged('error', 'Some variable did not contain a value.');
    }

    public function testEventTriggering()
    {
        Events::on('foo', static function ($arg) use (&$result) {
            $result = $arg;
        });

        Events::trigger('foo', 'bar');

        $this->assertEventTriggered('foo');
    }

    public function testStreamFilter()
    {
        CITestStreamFilter::$buffer = '';
        $this->stream_filter        = stream_filter_append(STDOUT, 'CITestStreamFilter');<commit_msg>add: setup function<commit_after><?php

/**
 * This file is part of CodeIgniter 4 framework.
 *
 * (c) CodeIgniter Foundation <<EMAIL>>
 *
 * For the full copyright and license information, please view
 * the LICENSE file that was distributed with this source code.
 */

namespace CodeIgniter\Test;

use CodeIgniter\CLI\CLI;
use CodeIgniter\Events\Events;
use CodeIgniter\HTTP\Response;
use CodeIgniter\Test\Filters\CITestStreamFilter;
use Config\App;

/**
 * @internal
 */
final class TestCaseTest extends CIUnitTestCase
{
    /**
     * @var bool|resource
     */
    private $stream_filter;

    protected function setUp(): void
    {
        parent::setUp();
    
        // Reset CLI::$lastWrite
        CLI::print();
    }

    public function testGetPrivatePropertyWithObject()
    {
        $obj    = new __TestForReflectionHelper();
        $actual = $this->getPrivateProperty($obj, 'private');
        $this->assertSame('secret', $actual);
    }

    public function testLogging()
    {
        log_message('error', 'Some variable did not contain a value.');
        $this->assertLogged('error', 'Some variable did not contain a value.');
    }

    public function testEventTriggering()
    {
        Events::on('foo', static function ($arg) use (&$result) {
            $result = $arg;
        });

        Events::trigger('foo', 'bar');

        $this->assertEventTriggered('foo');
    }

    public function testStreamFilter()
    {
        CITestStreamFilter::$buffer = '';
        $this->stream_filter        = stream_filter_append(STDOUT, 'CITestStreamFilter');
{'fraction_non_alphanumeric': 0.12570480928689884, 'fraction_numerical': 0.0006633499170812604, 'mean_word_length': 2.968421052631579, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, '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': '1193122', 'n_tokens_mistral': 868, 'n_tokens_neox': 854, 'n_words': 219}