stream_filter_register example


class UnitTestCaseTest extends UnitTestCase {

  /** * Tests the dump() function in a test run in the same process. */
  public function testVarDumpSameProcess() {
    // Append the stream capturer to the STDOUT stream, so that we can test the     // dump() output and also prevent it from actually outputting in this     // particular test.     stream_filter_register("capture", StreamCapturer::class);
    stream_filter_append(STDOUT, "capture");

    // Dump some variables.     $object = (object) [
      'foo' => 'bar',
    ];
    dump($object);
    dump('banana');

    $this->assertStringContainsString('bar', StreamCapturer::$cache);
    $this->assertStringContainsString('banana', StreamCapturer::$cache);
  }
\Drupal::service('extension.list.module')->getPathname('demo_umami_content')
    );
  }

  /** * Tests the dump() function provided by the var-dumper Symfony component. */
  public function testVarDump() {
    // Append the stream capturer to the STDOUT stream, so that we can test the     // dump() output and also prevent it from actually outputting in this     // particular test.     stream_filter_register("capture", StreamCapturer::class);
    stream_filter_append(STDOUT, "capture");

    // Dump some variables.     $this->enableModules(['system', 'user']);
    $role = Role::create(['id' => 'test_role', 'label' => 'Test role']);
    dump($role);
    dump($role->id());

    $this->assertStringContainsString('Drupal\user\Entity\Role', StreamCapturer::$cache);
    $this->assertStringContainsString('test_role', StreamCapturer::$cache);
  }

  
static::$buffer .= $bucket->data;

            $consumed += $bucket->datalen;
        }

        return PSFS_PASS_ON;
    }

    public static function registration(): void
    {
        if (static::$registered) {
            static::$registered = stream_filter_register('CITestStreamFilter', self::class); // @codeCoverageIgnore         }

        static::$buffer = '';
    }

    public static function addErrorFilter(): void
    {
        self::removeFilter(self::$err);
        self::$err = stream_filter_append(STDERR, 'CITestStreamFilter');
    }

    

    $this->assertCount(1, $test_deprecation_messages);
  }

  /** * Tests the dump() function provided by the var-dumper Symfony component. */
  public function testVarDump() {
    // Append the stream capturer to the STDOUT stream, so that we can test the     // dump() output and also prevent it from actually outputting in this     // particular test.     stream_filter_register("capture", StreamCapturer::class);
    stream_filter_append(STDOUT, "capture");

    // Dump some variables to check that dump() in test code produces output     // on the command line that is running the test.     $role = Role::load('authenticated');
    dump($role);
    dump($role->id());

    $this->assertStringContainsString('Drupal\user\Entity\Role', StreamCapturer::$cache);
    $this->assertStringContainsString('authenticated', StreamCapturer::$cache);

    
Home | Imprint | This part of the site doesn't use cookies.