Skip to content

Commit

Permalink
Add coverage to project (#6)
Browse files Browse the repository at this point in the history
* Add coverage to project

* Add tests for 100% coverage.

---------

Co-authored-by: david_smith <david_smith@sweetwater.com>
  • Loading branch information
zero-to-prod and david_smith authored Oct 26, 2024
1 parent 773c779 commit d0d34db
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 7 deletions.
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ services:
target: debug
volumes:
- ./:/app
- ./docker/php71:/usr/local/etc/php

php71composer:
build:
context: docker/php71
target: composer
volumes:
- ./:/app
- ./docker/php71:/usr/local/etc/php
- ./:/app
5 changes: 5 additions & 0 deletions docker/php71/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
FROM php:7.1-cli AS base

WORKDIR /app

RUN apt-get update && apt-get install -y \
git \
unzip \
&& rm -rf /var/lib/apt/lists/*

FROM base AS composer

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

FROM base AS debug

RUN pecl channel-update pecl.php.net && \
pecl install xdebug-2.9.8 && \
docker-php-ext-enable xdebug && \
echo "xdebug.mode=coverage" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \

WORKDIR /app

CMD ["bash"]
2 changes: 2 additions & 0 deletions docker/php71/php.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
zend_extension=xdebug.so
xdebug.mode=coverage
16 changes: 11 additions & 5 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php" colors="true">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
verbose="true">
<testsuites>
<testsuite name="Test Suite">
<directory suffix="Test.php">./tests</directory>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
</phpunit>
20 changes: 20 additions & 0 deletions tests/Unit/Make/FactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Tests\Unit\Make;

use Tests\TestCase;

class FactoryTest extends TestCase
{
/**
* @test
*
* @see Factory
*/
public function from(): void
{
$User = User::factory()->make();

self::assertEquals('John', $User->first_name);
}
}
18 changes: 18 additions & 0 deletions tests/Unit/Make/User.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Tests\Unit\Make;

use Tests\Unit\DataModel;

class User
{
use DataModel;

public const first_name = 'first_name';
public $first_name;

public static function factory(array $states = []): UserFactory
{
return new UserFactory($states);
}
}
19 changes: 19 additions & 0 deletions tests/Unit/Make/UserFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Tests\Unit\Make;

use Zerotoprod\DataModelFactory\Factory;

class UserFactory
{
use Factory;

protected $model = User::class;

protected function definition(): array
{
return [
User::first_name => 'John'
];
}
}

0 comments on commit d0d34db

Please sign in to comment.