Follows-up I361fde0de7f4406bce6ed075ed397effa5be3359. Per T253461, not mass-changing source code, but the use of the native error silencing operator (@) is especially useful in tests because: 1. It requires any/all statements to be explicitly marked. The suppressWarnings/restoreWarnings sections encourage developers to be "lazy" and thus encapsulate more than needed if there are multiple ones near each other, which would ignore potentially important warnings in a test case, which is generally exactly the time when it is really useful to get warnings etc. 2. It avoids leaking state, for example in LBFactoryTest the assertFalse call would throw a PHPUnit assertion error (not meant to be caught by the local catch), and thus won't reach AtEase::restoreWarnings. This then causes later code to end up in a mismatching state and creates a confusing error_reporting state. See .phpcs.xml, where the at operator is allowed for all test code. Change-Id: I68d1725d685e0a7586468bc9de6dc29ceea31b8a
52 lines
1.2 KiB
PHP
52 lines
1.2 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Code shared between the unit and integration tests
|
|
*/
|
|
trait TempFSFileTestTrait {
|
|
abstract protected function newFile();
|
|
|
|
/**
|
|
* @covers TempFSFile::__construct
|
|
* @covers TempFSFile::purge
|
|
*/
|
|
public function testPurge() {
|
|
$file = $this->newFile();
|
|
$this->assertTrue( is_file( $file->getPath() ) );
|
|
$file->purge();
|
|
$this->assertFalse( is_file( $file->getPath() ) );
|
|
}
|
|
|
|
/**
|
|
* @covers TempFSFile::__construct
|
|
* @covers TempFSFile::bind
|
|
* @covers TempFSFile::autocollect
|
|
* @covers TempFSFile::__destruct
|
|
*/
|
|
public function testBind() {
|
|
$file = $this->newFile();
|
|
$path = $file->getPath();
|
|
$this->assertTrue( is_file( $path ) );
|
|
$obj = (object)[];
|
|
$file->bind( $obj );
|
|
unset( $file );
|
|
$this->assertTrue( is_file( $path ) );
|
|
unset( $obj );
|
|
$this->assertFalse( is_file( $path ) );
|
|
}
|
|
|
|
/**
|
|
* @covers TempFSFile::__construct
|
|
* @covers TempFSFile::preserve
|
|
* @covers TempFSFile::__destruct
|
|
*/
|
|
public function testPreserve() {
|
|
$file = $this->newFile();
|
|
$path = $file->getPath();
|
|
$this->assertTrue( is_file( $path ) );
|
|
$file->preserve();
|
|
unset( $file );
|
|
$this->assertTrue( is_file( $path ) );
|
|
@unlink( $path );
|
|
}
|
|
}
|