Commit 3147b561 authored by Karamel's avatar Karamel
Browse files

Make tests compatible with PHPUnit 9.0.

parent 07c1d3c8
......@@ -39,13 +39,13 @@ class APIHelperTest extends TestCase
private $dao;
private $api;
protected function setUp() {
protected function setUp(): void {
global $dbInfo;
$this->dao = DAOFactory::getDAO($dbInfo, ['debug' => true]);
$this->api = new APIHelperMock($this->dao);
}
protected function tearDown() {
protected function tearDown(): void {
$all = $this->dao->search(APIHelperMock::MODEL_NAME, null);
foreach ($all as $record) {
$this->dao->delete($record);
......@@ -150,13 +150,13 @@ class APIHelperTest extends TestCase
$this->checkEquality($cat2, $read2);
}
/** @expectedException \InvalidArgumentException */
public function testWriteInvalid() {
$this->expectException(\InvalidArgumentException::class);
$this->api->write($this->dao);
}
/** @expectedException \InvalidArgumentException */
public function testWriteArrayInvalid() {
$this->expectException(\InvalidArgumentException::class);
$cat = new Category();
$cat->setReference('ref1');
$cat->setLabel('Test1');
......
......@@ -38,13 +38,13 @@ class APIRefHelperTest extends TestCase
private $dao;
private $api;
protected function setUp() {
protected function setUp(): void {
global $dbInfo;
$this->dao = DAOFactory::getDAO($dbInfo, ['debug' => true]);
$this->api = new APIRefHelperMock($this->dao);
}
protected function tearDown() {
protected function tearDown(): void {
$all = $this->api->getAll();
$ids = array();
foreach($all as $record) {
......
......@@ -49,7 +49,7 @@ class CashsessionAPITest extends TestCase
private $api;
private $tax;
protected function setUp() {
protected function setUp(): void {
global $dbInfo;
$this->dao = DAOFactory::getDAO($dbInfo, ['debug' => true]);
$this->api = new CashsessionAPIProxy($this->dao);
......@@ -64,7 +64,7 @@ class CashsessionAPITest extends TestCase
$this->dao->commit();
}
protected function tearDown() {
protected function tearDown(): void {
$taxes = $this->dao->search(CashSessionTax::class);
foreach ($taxes as $tax) { $this->dao->delete($tax); }
$all = $this->dao->search(CashSession::class);
......@@ -332,10 +332,10 @@ class CashsessionAPITest extends TestCase
$this->assertEquals(0, count($next->getTaxes()));
}
/** @depends testWrite
* @expectedException \BadMethodCallException
* @expectedExceptionMessage Trying to close a session that was not registered as open. */
/** @depends testWrite */
public function testWriteClosed() {
$this->expectException(\BadMethodCallException::class);
$this->expectExceptionMessage('Trying to close a session that was not registered as open.');
$session = new CashSession();
$session->setCashRegister($this->cashRegister);
$session->setSequence(1);
......@@ -370,10 +370,10 @@ class CashsessionAPITest extends TestCase
}
}
/** @depends testWriteClosed
* @expectedException \BadMethodCallException
* @expectedExceptionMessage Trying to close a session that was not registered as open. */
/** @depends testWriteClosed */
public function testFailTwice() {
$this->expectException(\BadMethodCallException::class);
$this->expectExceptionMessage('Trying to close a session that was not registered as open.');
$session = new CashSession();
$session->setCashRegister($this->cashRegister);
$session->setSequence(1);
......@@ -421,10 +421,10 @@ class CashsessionAPITest extends TestCase
}
}
/** @depends testWrite
* @expectedException \BadMethodCallException
* @expectedExceptionMessage Closed sessions are read-only. */
/** @depends testWrite */
public function testOverwriteClosed() {
$this->expectException(\BadMethodCallException::class);
$this->expectExceptionMessage('Closed sessions are read-only');
$session = new CashSession();
$session->setCashRegister($this->cashRegister);
$session->setSequence(1);
......
......@@ -34,13 +34,13 @@ class CategoryAPITest extends TestCase
private $dao;
private $api;
protected function setUp() {
protected function setUp(): void {
global $dbInfo;
$this->dao = DAOFactory::getDAO($dbInfo, ['debug' => true]);
$this->api = new CategoryAPI($this->dao);
}
protected function tearDown() {
protected function tearDown(): void {
// Explicitely delete children before parents because Doctrine
// cannot handle it. It won't work if there grandchildren.
$children = $this->dao->search(Category::class,
......
......@@ -33,13 +33,13 @@ class CurrencyAPITest extends TestCase
private $dao;
private $api;
protected function setUp() {
protected function setUp(): void {
global $dbInfo;
$this->dao = DAOFactory::getDAO($dbInfo, ['debug' => true]);
$this->api = new CurrencyAPI($this->dao);
}
protected function tearDown() {
protected function tearDown(): void {
$all = $this->dao->search(Currency::class);
foreach($all as $record) {
$this->dao->delete($record);
......@@ -82,8 +82,8 @@ class CurrencyAPITest extends TestCase
$this->assertFalse($readOther->isMain());
}
/** @expectedException \BadMethodCallException */
public function testDeleteMain() {
$this->expectException(\BadMethodCallException::class);
$main = new Currency();
$main->setReference('main');
$main->setLabel('Main');
......@@ -97,8 +97,8 @@ class CurrencyAPITest extends TestCase
$this->api->delete($main->getId());
}
/** @expectedException \BadMethodCallException */
public function testUnsetMain() {
$this->expectException(\BadMethodCallException::class);
$main = new Currency();
$main->setReference('main');
$main->setLabel('Main');
......
......@@ -33,13 +33,13 @@ class CustomerAPITest extends TestCase
private $dao;
private $api;
protected function setUp() {
protected function setUp(): void {
global $dbInfo;
$this->dao = DAOFactory::getDAO($dbInfo, ['debug' => true]);
$this->api = new CustomerAPI($this->dao);
}
protected function tearDown() {
protected function tearDown(): void {
$all = $this->dao->search(Customer::class);
foreach($all as $record) {
$this->dao->delete($record);
......
......@@ -49,7 +49,7 @@ class ImageAPITest extends TestCase
private $customer;
private $paymentMode;
protected function setUp() {
protected function setUp(): void {
global $dbInfo;
$this->dao = DAOFactory::getDAO($dbInfo, ['debug' => true]);
$this->api = new ImageAPI(null, $this->dao);
......@@ -88,7 +88,7 @@ class ImageAPITest extends TestCase
$this->dao->commit();
}
protected function tearDown() {
protected function tearDown(): void {
$all = $this->dao->search(Image::class);
foreach($all as $record) {
$this->dao->delete($record);
......@@ -143,9 +143,9 @@ class ImageAPITest extends TestCase
$this->defaultTest(Image::MODEL_PAYMENTMODE_VALUE, 'default_generic.png', 'image/png');
}
/** @expectedException \BadMethodCallException
* @expectedExceptionMessage Unknown model cow */
public function testDefaultUnknownModel() {
$this->expectException(\BadMethodCallException::class);
$this->expectExceptionMessage('Unknown model cow');
$this->api->getDefault('cow');
}
......@@ -211,16 +211,16 @@ class ImageAPITest extends TestCase
$this->assertNotNull($snapImg);
}
/** @expectedException BadMethodCallException
* @expectedExceptionMessage Unknown model cow */
public function testSetImageWrongModel() {
$this->expectException(\BadMethodCallException::class);
$this->expectExceptionMessage('Unknown model cow');
$img = $this->sampleImage('cow', $this->cat->getId());
$this->api->write($img);
}
/** @expectedException BadMethodCallException
* @expectedExceptionMessage category:0 not found */
public function testSetImageInexistingModel() {
$this->expectException(\BadMethodCallException::class);
$this->expectExceptionMessage('category:0 not found');
$img = $this->sampleImage(Image::MODEL_CATEGORY, 0);
$this->api->write($img);
}
......@@ -284,9 +284,9 @@ class ImageAPITest extends TestCase
$this->assertNull($snapImg);
}
/** @expectedException BadMethodCallException
* @expectedExceptionMessage Unknown model cow */
public function testDeleteImageWrongModel() {
$this->expectException(\BadMethodCallException::class);
$this->expectExceptionMessage('Unknown model cow');
$img = $this->sampleImage('cow', $this->cat->getId());
$this->api->delete($img->getId());
}
......
......@@ -37,13 +37,13 @@ class PaymentModeAPITest extends TestCase
private $dao;
private $api;
protected function setUp() {
protected function setUp(): void {
global $dbInfo;
$this->dao = DAOFactory::getDAO($dbInfo, ['debug' => true]);
$this->api = new PaymentModeAPI($this->dao);
}
protected function tearDown() {
protected function tearDown(): void {
$imgs = $this->dao->search(Image::class);
foreach ($imgs as $img) {
$this->dao->delete($img);
......
......@@ -34,13 +34,13 @@ class PlaceAPITest extends TestCase
private $dao;
private $api;
protected function setUp() {
protected function setUp(): void {
global $dbInfo;
$this->dao = DAOFactory::getDAO($dbInfo, ['debug' => true]);
$this->api = new PlaceAPI($this->dao);
}
protected function tearDown() {
protected function tearDown(): void {
$places = $this->dao->search(Place::class);
foreach ($places as $record) {
$this->dao->delete($record);
......
......@@ -37,7 +37,7 @@ class ProductAPITest extends TestCase
private $dao;
private $api;
protected function setUp() {
protected function setUp(): void {
global $dbInfo;
$this->dao = DAOFactory::getDAO($dbInfo, ['debug' => true]);
$this->api = new ProductAPI($this->dao);
......@@ -56,7 +56,7 @@ class ProductAPITest extends TestCase
$this->dao->commit();
}
protected function tearDown() {
protected function tearDown(): void {
$cmpPrds = $this->dao->search(CompositionProduct::class);
foreach ($cmpPrds as $record) {
$this->dao->delete($record);
......@@ -214,15 +214,15 @@ class ProductAPITest extends TestCase
$this->assertEquals($prd2->getId(), $read[0]->getId());
}
/** @expectedException \InvalidArgumentException
* Pass pure garbage to the function. */
/** Pass pure garbage to the function. */
public function testGetFromCategoryGarbage() {
$this->expectException(\InvalidArgumentException::class);
$this->api->getFromCategory(array('I', 'am', 'Garbage'));
}
/** @expectedException \InvalidArgumentException
* Pass an other DoctrineModel to the API. */
/* Pass an other DoctrineModel to the API. */
public function testGetFromCategoryOtherGarbage() {
$this->expectException(\InvalidArgumentException::class);
$prd = new Product();
$prd->setReference('Ref');
$prd->setLabel('Label');
......
......@@ -37,7 +37,7 @@ class TariffAreaAPITest extends TestCase
private $dao;
private $api;
protected function setUp() {
protected function setUp(): void {
global $dbInfo;
$this->dao = DAOFactory::getDAO($dbInfo, ['debug' => true]);
$this->api = new TariffareaAPI($this->dao);
......@@ -53,7 +53,7 @@ class TariffAreaAPITest extends TestCase
$this->dao->commit();
}
protected function tearDown() {
protected function tearDown(): void {
$prices = $this->dao->search(TariffAreaPrice::class);
foreach ($prices as $record) {
$this->dao->delete($record);
......
......@@ -70,7 +70,7 @@ class TicketAPITest extends TestCase
private $role;
private $user;
protected function setUp() {
protected function setUp(): void {
global $dbInfo;
$this->dao = DAOFactory::getDAO($dbInfo, ['debug' => true]);
$this->api = new TicketAPIProxy($this->dao);
......@@ -117,7 +117,7 @@ class TicketAPITest extends TestCase
$this->dao->commit();
}
protected function tearDown() {
protected function tearDown(): void {
foreach ([FiscalTicket::class, TicketPayment::class, TicketTax::class,
TicketLine::class, Ticket::class, Customer::class,
CashSession::class, CashRegister::class, User::class,
......@@ -213,9 +213,9 @@ class TicketAPITest extends TestCase
$this->assertTrue($eos->checkSignature($ft2));
}
/** @expectedException \BadMethodCallException
* @expectedExceptionMessage Ticket number 0 is reserved. */
public function testSaveTicket0() {
$this->expectException(\BadMethodCallException::class);
$this->expectExceptionMessage('Ticket number 0 is reserved.');
$line1 = TicketLine::fromStruct(['dispOrder' => 1,
'taxedUnitPrice' => 11.0,
'quantity' => 1, 'tax' => $this->tax->getId(),
......@@ -309,10 +309,10 @@ class TicketAPITest extends TestCase
}
/** @depends testSaveTicket
* @expectedException \BadMethodCallException
* @expectedExceptionMessage Tickets are read only.
* Test writing two identical tickets (without sharing references). */
public function testSaveDoubleTicket() {
$this->expectException(\BadMethodCallException::class);
$this->expectExceptionMessage('Tickets are read only.');
$line11 = TicketLine::fromStruct(['dispOrder' => 1,
'taxedUnitPrice' => 11.0,
'quantity' => 1, 'tax' => $this->tax->getId(),
......@@ -445,9 +445,9 @@ class TicketAPITest extends TestCase
}
/** @depends testSaveTicketOverwrite
* @expectedException \BadMethodCallException
* Test failing the same ticket twice to check that 2 rejects are saved. */
public function testFailTwice() {
$this->expectException(\BadMethodCallException::class);
$line1 = TicketLine::fromStruct(['dispOrder' => 1,
'taxedUnitPrice' => 11.0,
'quantity' => 1, 'tax' => $this->tax->getId(),
......@@ -513,9 +513,9 @@ class TicketAPITest extends TestCase
}
/** @depends testSaveTicket
* @expectedException \BadMethodCallException
* Test writing a ticket with invalid data (twice the same line number) */
public function testSaveScrewedTicket() {
$this->expectException(\BadMethodCallException::class);
$line1 = TicketLine::fromStruct(['dispOrder' => 1,
'taxedUnitPrice' => 11.0,
'quantity' => 1, 'tax' => $this->tax->getId(),
......@@ -554,10 +554,10 @@ class TicketAPITest extends TestCase
$this->api->write($tkt);
}
/** @depends testSaveTicket
* @expectedException \BadMethodCallException
* @expectedExceptionMessage Tickets must be assigned to an opened cash session */
/** @depends testSaveTicket */
public function testSaveTicketClosedCash() {
$this->expectException(\BadMethodCallException::class);
$this->expectExceptionMessage('Tickets must be assigned to an opened cash session');
$sess = $this->dao->read(CashSession::class, $this->session->getId());
$sess->setCloseDate(new \DateTime('2018-01-01 8:00'));
$this->dao->write($sess); // as well, editing $this->sesssion doesn't work
......
......@@ -35,7 +35,7 @@ class UserAPITest extends TestCase
private $api;
private $role;
protected function setUp() {
protected function setUp(): void {
global $dbInfo;
$this->dao = DAOFactory::getDAO($dbInfo, ['debug' => true]);
$this->api = new UserAPI($this->dao);
......@@ -45,7 +45,7 @@ class UserAPITest extends TestCase
$this->dao->commit();
}
protected function tearDown() {
protected function tearDown(): void {
$users = $this->dao->search(User::class);
foreach ($users as $record) {
$this->dao->delete($record);
......
......@@ -33,13 +33,13 @@ class VersionAPITest extends TestCase
private $dao;
private $api;
protected function setUp() {
protected function setUp(): void {
global $dbInfo;
$this->dao = DAOFactory::getDAO($dbInfo, ['debug' => true]);
$this->api = new VersionAPI($this->dao);
}
protected function tearDown() {
protected function tearDown(): void {
$all = $this->dao->search(Option::class);
foreach($all as $record) {
$this->dao->delete($record);
......@@ -48,15 +48,15 @@ class VersionAPITest extends TestCase
$this->dao->close();
}
/** @expectedException \UnexpectedValueException
* @expectedExceptionMessage dblevel option does not exist. The database is probably not initialized. */
public function testGetNoValue() {
$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessage('dblevel option does not exist. The database is probably not initialized.');
$version = $this->api->get();
}
/** @expectedException \UnexpectedValueException
* @expectedExceptionMessage dblevel abc option is invalid. */
public function testGetInvalidValue() {
$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessage('dblevel abc option is invalid.');
$opt = new Option();
$opt->setName('dblevel');
$opt->setSystem(true);
......@@ -96,15 +96,15 @@ class VersionAPITest extends TestCase
$this->assertEquals(4, $version->get('level'));
}
/** @expectedException \InvalidArgumentException
* @expectedExceptionMessage Invalid level value. */
public function testSetNull() {
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid level value.');
$this->api->setLevel(null);
}
/** @expectedException \InvalidArgumentException
* @expectedExceptionMessage Invalid level value. */
public function testSetZero() {
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid level value.');
$this->api->setLevel(0);
}
......
......@@ -39,7 +39,7 @@ require_once(dirname(dirname(__FILE__)) . "/common_load.php");
/** Test for CashSession and its subclasses CashSessionCat, CashSessionTax... */
class CashSessionTest extends TestCase
{
protected function setUp() {
protected function setUp(): void {
global $dbInfo;
$this->dao = DAOFactory::getDAO($dbInfo, ['debug' => true]);
$this->cashRegister = new CashRegister();
......@@ -65,7 +65,7 @@ class CashSessionTest extends TestCase
$this->dao->commit();
}
protected function tearDown() {
protected function tearDown(): void {
foreach ([CashSessionCat::class, CashSessionCustBalance::class,
CashSessionTax::class, CashSession::class] as $class) {
$all = $this->dao->search($class);
......@@ -98,10 +98,10 @@ class CashSessionTest extends TestCase
// No exception thrown
}
/** @depends testSetOpenDate
* @expectedException \UnexpectedValueException
* @expectedExceptionMessage Open date is read only */
/** @depends testSetOpenDate */
public function testOverwriteOpenDate() {
$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessage('Open date is read only');
$session = new CashSession();
$session->setCashRegister($this->cashRegister);
$session->setSequence(1);
......@@ -138,10 +138,10 @@ class CashSessionTest extends TestCase
// No exception thrown
}
/** @depends testSetCloseDate
* @expectedException \UnexpectedValueException
* @expectedExceptionMessage Close date is read only */
/** @depends testSetCloseDate */
public function testOverwriteCloseDate() {
$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessage('Close date is read only');
$session = new CashSession();
$session->setCashRegister($this->cashRegister);
$session->setSequence(1);
......@@ -178,10 +178,10 @@ class CashSessionTest extends TestCase
// No exception thrown.
}
/** @depends testSetOpenCash
* @expectedException \UnexpectedValueException
* @expectedExceptionMessage Open cash is read only */
/** @depends testSetOpenCash */
public function testOverwriteOpenCash() {
$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessage('Open cash is read only');
$session = new CashSession();
$session->setCashRegister($this->cashRegister);
$session->setSequence(1);
......@@ -207,10 +207,10 @@ class CashSessionTest extends TestCase
// No exception thrown.
}
/** @depends testSetCloseCash
* @expectedException \UnexpectedValueException
* @expectedExceptionMessage Close cash is read only */
/** @depends testSetCloseCash */
public function testOverwriteCloseCash() {
$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessage('Close cash is read only');
$session = new CashSession();
$session->setCashRegister($this->cashRegister);
$session->setSequence(1);
......@@ -249,10 +249,10 @@ class CashSessionTest extends TestCase
// No exception thrown.
}
/** @depends testSetTicketCount
* @expectedException \UnexpectedValueException
* @expectedExceptionMessage Ticket count is read only */
/** @depends testSetTicketCount */
public function testOverwriteTicketCount() {
$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessage('Ticket count is read only');
$session = new CashSession();
$session->setCashRegister($this->cashRegister);
$session->setSequence(1);
......@@ -277,10 +277,10 @@ class CashSessionTest extends TestCase
// No exception thrown.
}
/** @depends testSetCustCount
* @expectedException \UnexpectedValueException
* @expectedExceptionMessage Customer count is read only */
/** @depends testSetCustCount */
public function testOverwriteCustCount() {
$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessage('Customer count is read only');
$session = new CashSession();
$session->setCashRegister($this->cashRegister);
$session->setSequence(1);
......@@ -305,10 +305,10 @@ class CashSessionTest extends TestCase
// No exception thrown.
}
/** @depends testSetCS
* @expectedException \UnexpectedValueException
* @expectedExceptionMessage Consolidated sales is read only */
/** @depends testSetCS */
public function testOverwriteCS() {
$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessage('Consolidated sales is read only');
$session = new CashSession();
$session->setCashRegister($this->cashRegister);
$session->setSequence(1);
......@@ -332,8 +332,8 @@ class CashSessionTest extends TestCase
'custBalances' => []];
}
/** @expectedException \UnexpectedValueException */
public function testFromStructPreventNewSession() {
$this->expectException(\UnexpectedValueException::class);
$session = $this->initEmptySession();
$struct = ['cashRegister' => $this->cashRegister->getId(),
'sequence' => 2];
......
......@@ -33,12 +33,12 @@ class CategoryTest extends TestCase
{
private $dao;
protected function setUp() {
protected function setUp(): void {
global $dbInfo;
$this->dao = DAOFactory::getDAO($dbInfo, ['debug' => true]);
}
protected function tearDown() {