1
0
mirror of https://github.com/danog/loop.git synced 2024-11-26 20:04:44 +01:00
loop/test/Fixtures.php

74 lines
2.0 KiB
PHP
Raw Normal View History

2022-12-24 14:36:39 +01:00
<?php declare(strict_types=1);
2020-07-21 19:53:57 +02:00
/**
* Loop test.
*
* @author Daniil Gentili <daniil@daniil.it>
* @copyright 2016-2020 Daniil Gentili <daniil@daniil.it>
* @license https://opensource.org/licenses/MIT MIT
*/
namespace danog\Loop\Test;
2023-01-23 00:24:18 +01:00
use danog\Loop\Loop;
2020-07-21 19:53:57 +02:00
use danog\Loop\Test\Interfaces\BasicInterface;
/**
* Fixtures.
*/
2023-01-24 03:49:03 +01:00
abstract class Fixtures extends \PHPUnit\Framework\TestCase
2020-07-21 19:53:57 +02:00
{
2022-12-24 18:30:29 +01:00
const LOOP_NAME = 'TTTT';
2020-07-21 19:53:57 +02:00
/**
* Execute pre-start assertions.
*/
2023-01-23 00:24:18 +01:00
protected function assertPreStart(BasicInterface&Loop $loop): void
2020-07-21 19:53:57 +02:00
{
$this->assertEquals(self::LOOP_NAME, "$loop");
$this->assertFalse($loop->isRunning());
$this->assertFalse($loop->ran());
$this->assertFalse($loop->inited());
$this->assertEquals(0, $loop->startCounter());
$this->assertEquals(0, $loop->endCounter());
}
/**
* Execute after-start assertions.
*
* @param bool $running Whether we should expect the loop to be running
2022-12-24 18:49:23 +01:00
* @param bool $running Whether we should actually start the loop by returning control to the event loop
2020-07-21 19:53:57 +02:00
*
*/
2023-01-23 00:24:18 +01:00
protected function assertAfterStart(BasicInterface&Loop $loop, bool $running = true, bool $start = true): void
2020-07-21 19:53:57 +02:00
{
2022-12-24 18:49:23 +01:00
if ($start) {
2023-01-24 03:49:03 +01:00
LoopTest::waitTick();
2022-12-24 18:49:23 +01:00
}
2020-07-21 19:53:57 +02:00
$this->assertTrue($loop->inited());
if ($running) {
$this->assertFalse($loop->ran());
}
2022-12-24 18:16:45 +01:00
$this->assertEquals($running, $loop->isRunning());
2020-07-21 19:53:57 +02:00
$this->assertEquals(1, $loop->startCounter());
$this->assertEquals($running ? 0 : 1, $loop->endCounter());
$this->assertEquals($running, !$loop->start());
}
/**
* Execute final assertions.
*/
2023-01-23 00:24:18 +01:00
protected function assertFinal(BasicInterface&Loop $loop): void
2020-07-21 19:53:57 +02:00
{
$this->assertTrue($loop->ran());
$this->assertFalse($loop->isRunning());
$this->assertTrue($loop->inited());
$this->assertEquals(1, $loop->startCounter());
$this->assertEquals(1, $loop->endCounter());
}
}