barracudanetworks / ArchiveStream-php

Archive streaming library for PHP
Other
77 stars 27 forks source link

Add a way to not disable output buffering #50

Open Rudloff opened 5 years ago

Rudloff commented 5 years ago

The Archive constructor calls ob_end_clean(): https://github.com/barracudanetworks/ArchiveStream-php/blob/87540ce2b53257e2fd6505f4b261dc22b82d77c6/src/Archive.php#L94

I get why you do this but it causes problems with phpunit tests (because it uses output buffering to know what the tested code outputted):

Test code or tested code did not (only) close its own output buffers

Would it be possible to add an argument to not disable output buffering?

johnmaguire commented 5 years ago

For the purposes of testing, I believe you can mock out the function by doing something like this in your test file:

<?php

namespace Barracuda\ArchiveStream {
  function ob_end_clean()
  {
  }
}

namespace my\test\namespace {
    # Test code that invokes ArchiveStream here
}

This overrides ob_end_clean with a no-op function inside the ArchiveStream namespace so you won't get errors.