Require @covers annotation for tests, increase workspace mem limit to 512M, improved coverage for db factories

This commit is contained in:
Igor Scheller 2022-06-02 13:18:37 +02:00
parent 724894316a
commit b41a675a35
5 changed files with 47 additions and 14 deletions

View File

@ -147,7 +147,7 @@ test:
- ./bin/migrate - ./bin/migrate
script: script:
- >- - >-
php -d pcov.enabled=1 vendor/bin/phpunit -vvv --colors=never php -d pcov.enabled=1 -d pcov.directory=. vendor/bin/phpunit -vvv --colors=never
--coverage-text --coverage-html "${HOMEDIR}/coverage/" --coverage-text --coverage-html "${HOMEDIR}/coverage/"
--log-junit "${HOMEDIR}/unittests.xml" --log-junit "${HOMEDIR}/unittests.xml"
after_script: after_script:

View File

@ -55,7 +55,7 @@ vendor/bin/phpunit
To run code coverage reports its highly recommended to use [`pcov`](https://github.com/krakjoe/pcov) or To run code coverage reports its highly recommended to use [`pcov`](https://github.com/krakjoe/pcov) or
at least `phpdbg -qrr`(which has problems with switch case statements) as using Xdebug slows down execution. at least `phpdbg -qrr`(which has problems with switch case statements) as using Xdebug slows down execution.
```bash ```bash
php -d pcov.enabled=1 vendor/bin/phpunit --testsuite Unit --coverage-text php -d pcov.enabled=1 -d pcov.directory=. vendor/bin/phpunit --testsuite Unit --coverage-text
``` ```
### Var Dump server ### Var Dump server

View File

@ -24,6 +24,7 @@ ENV TRUSTED_PROXIES 10.0.0.0/8,::ffff:10.0.0.0/8,\
# Engelsystem development workspace # Engelsystem development workspace
# Contains all tools required to build / manage the system # Contains all tools required to build / manage the system
FROM es_base AS es_workspace FROM es_base AS es_workspace
RUN echo 'memory_limit = 512M' > /usr/local/etc/php/conf.d/docker-php.ini
RUN apk add --no-cache gettext nodejs npm yarn RUN apk add --no-cache gettext nodejs npm yarn
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
ENTRYPOINT php -r 'sleep(PHP_INT_MAX);' ENTRYPOINT php -r 'sleep(PHP_INT_MAX);'

View File

@ -1,21 +1,22 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<phpunit <phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
bootstrap="./includes/autoload.php" bootstrap="./includes/autoload.php"
forceCoversAnnotation="true"
colors="true" colors="true"
> >
<testsuites> <testsuites>
<testsuite name="Feature"> <testsuite name="Feature">
<directory>./tests/Feature</directory> <directory>tests/Feature</directory>
</testsuite> </testsuite>
<testsuite name="Unit"> <testsuite name="Unit">
<directory>./tests/Unit</directory> <directory>tests/Unit</directory>
</testsuite> </testsuite>
</testsuites> </testsuites>
<coverage> <coverage>
<include> <include>
<directory>./src/</directory> <directory>src</directory>
</include> </include>
</coverage> </coverage>
</phpunit> </phpunit>

View File

@ -10,6 +10,7 @@ use Engelsystem\Models\Question;
use Engelsystem\Models\Room; use Engelsystem\Models\Room;
use Engelsystem\Models\Shifts\Schedule; use Engelsystem\Models\Shifts\Schedule;
use Engelsystem\Models\User\Contact; use Engelsystem\Models\User\Contact;
use Engelsystem\Models\User\License;
use Engelsystem\Models\User\PasswordReset; use Engelsystem\Models\User\PasswordReset;
use Engelsystem\Models\User\PersonalData; use Engelsystem\Models\User\PersonalData;
use Engelsystem\Models\User\Settings; use Engelsystem\Models\User\Settings;
@ -24,24 +25,41 @@ class FactoriesTest extends TestCase
/** @var string[] */ /** @var string[] */
protected $models = [ protected $models = [
User::class,
Contact::class, Contact::class,
PersonalData::class, Faq::class,
Settings::class, License::class,
State::class, Message::class,
PasswordReset::class,
Worklog::class,
News::class, News::class,
NewsComment::class, NewsComment::class,
Message::class, PasswordReset::class,
Faq::class, PersonalData::class,
Question::class, Question::class,
Room::class, Room::class,
Schedule::class, Schedule::class,
Settings::class,
State::class,
User::class,
Worklog::class,
]; ];
/** /**
* Test all existing model factories * Test all existing model factories
*
* @covers \Database\Factories\Engelsystem\Models\User\ContactFactory
* @covers \Database\Factories\Engelsystem\Models\FaqFactory
* @covers \Database\Factories\Engelsystem\Models\User\LicenseFactory
* @covers \Database\Factories\Engelsystem\Models\MessageFactory
* @covers \Database\Factories\Engelsystem\Models\NewsFactory
* @covers \Database\Factories\Engelsystem\Models\NewsCommentFactory
* @covers \Database\Factories\Engelsystem\Models\User\PasswordResetFactory
* @covers \Database\Factories\Engelsystem\Models\User\PersonalDataFactory
* @covers \Database\Factories\Engelsystem\Models\QuestionFactory
* @covers \Database\Factories\Engelsystem\Models\RoomFactory
* @covers \Database\Factories\Engelsystem\Models\Shifts\ScheduleFactory
* @covers \Database\Factories\Engelsystem\Models\User\SettingsFactory
* @covers \Database\Factories\Engelsystem\Models\User\StateFactory
* @covers \Database\Factories\Engelsystem\Models\User\UserFactory
* @covers \Database\Factories\Engelsystem\Models\WorklogFactory
*/ */
public function testFactories() public function testFactories()
{ {
@ -52,4 +70,17 @@ class FactoriesTest extends TestCase
$this->assertInstanceOf(Model::class, $instance); $this->assertInstanceOf(Model::class, $instance);
} }
} }
/**
* @covers \Database\Factories\Engelsystem\Models\User\StateFactory
*/
public function testStateFactoryArrived()
{
$this->initDatabase();
/** @var State $instance */
$instance = (new State())->factory()->arrived()->create();
$this->assertInstanceOf(Model::class, $instance);
$this->assertTrue($instance->arrived);
}
} }