Skip to content

Commit

Permalink
First tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklog committed Jan 9, 2021
1 parent abe31f2 commit bfb2ccf
Show file tree
Hide file tree
Showing 6 changed files with 207 additions and 15 deletions.
11 changes: 0 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
.phpcs.cache
docker-compose.override.yml
build/
phpunit.xml
parameters.yml
version
composer/
Expand All @@ -24,13 +23,3 @@ var/
npm-debug.log
yarn-error.log
###< symfony/webpack-encore-bundle ###

###> squizlabs/php_codesniffer ###
/.phpcs-cache
/phpcs.xml
###< squizlabs/php_codesniffer ###

###> phpunit/phpunit ###
/phpunit.xml
.phpunit.result.cache
###< phpunit/phpunit ###
7 changes: 3 additions & 4 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

Your private self-hosted composer repository.

[![buymeacoffee](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/nicklog)
[![Buy me a coffee](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/nicklog)

[![License](https://img.shields.io/docker/cloud/build/nicklog/devliver.svg?style=flat-square&logo=docker)](https://hub.docker.com/r/nicklog/devliver)
[![Docker Build](https://img.shields.io/docker/cloud/build/nicklog/devliver.svg?style=flat-square&logo=docker)](https://hub.docker.com/r/nicklog/devliver)
[![License](https://img.shields.io/github/license/nicklog/devliver.svg?style=flat-square&logo=license)](https://github.com/nicklog/devliver)

[comment]: <> ([![License]&#40;https://img.shields.io/docker/build/nicklog/devliver.svg&#41;]&#40;https://hub.docker.com/r/nicklog/devliver&#41;)

## Requirements

Expand Down Expand Up @@ -63,7 +62,7 @@ When you want to secure it I suggest to use a reverse proxy.
## User

On first call of the website you can create a user. Create one and then login.
The first user becomes an admin and can create more user im necessary.
The first user becomes an admin and can create more user if necessary.

## Clients

Expand Down
36 changes: 36 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">

<arg value="p"/>
<arg value="s"/>
<arg name="colors"/>
<arg name="parallel" value="4"/>
<arg name="cache" value="./.phpcs.cache"/>

<file>bin/</file>
<file>src/</file>
<file>tests/</file>

<rule ref="./vendor/doctrine/coding-standard/lib/Doctrine/ruleset.xml">
<exclude name="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming.SuperfluousSuffix"/>
<exclude name="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming.SuperfluousPrefix"/>
<exclude name="Squiz.Arrays.ArrayDeclaration.MultiLineNotAllowed"/>
</rule>

<rule ref="Squiz.WhiteSpace.MemberVarSpacing">
<properties>
<property name="spacing" value="1" />
<property name="spacingBeforeFirst" value="0" />
</properties>
</rule>

<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="160"/>
</properties>
</rule>

<rule ref="Squiz.Arrays.ArrayDeclaration.DoubleArrowNotAligned">
<severity>5</severity>
</rule>
</ruleset>
33 changes: 33 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- https://phpunit.readthedocs.io/en/latest/configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="./tests/bootstrap.php"
beStrictAboutChangesToGlobalState="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutResourceUsageDuringSmallTests="true"
beStrictAboutTodoAnnotatedTests="true"
beStrictAboutCoversAnnotation="false"
forceCoversAnnotation="true"
enforceTimeLimit="true"
cacheResultFile="./var/cache/phpunit.unit.result.cache"
failOnRisky="true"
failOnWarning="true"
timeoutForSmallTests="2"
colors="true"
verbose="true"
printerClass="NunoMaduro\Collision\Adapters\Phpunit\Printer"
>
<php>
<server name="KERNEL_CLASS" value="App\Kernel" />
<server name="APP_ENV" value="test" />
</php>


<testsuites>
<testsuite name="Project Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
46 changes: 46 additions & 0 deletions tests/Collection/PackageCollectionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

namespace Collection;

use App\Collection\PackageCollection;
use Composer\Package\PackageInterface;
use PHPUnit\Framework\TestCase;

/**
* @covers \App\Collection\PackageCollection
*/
final class PackageCollectionTest extends TestCase
{
public function testLastStable(): void
{
$packageDev = $this->createMock(PackageInterface::class);
$packageDev->method('isDev')->willReturn(true);

$packageStable = $this->createMock(PackageInterface::class);
$packageStable->method('isDev')->willReturn(false);

$collection = PackageCollection::create(
$packageDev,
$packageStable
);

self::assertSame($packageStable, $collection->getLastStablePackage());
}

public function testLastStableNotFound(): void
{
$packageDev = $this->createMock(PackageInterface::class);
$packageDev->method('isDev')->willReturn(true);

$packageStable = $this->createMock(PackageInterface::class);
$packageStable->method('isDev')->willReturn(true);
$collection = PackageCollection::create(
$packageDev,
$packageStable
);

self::assertNull($collection->getLastStablePackage());
}
}
89 changes: 89 additions & 0 deletions tests/Collection/VersionCollectionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

declare(strict_types=1);

namespace Collection;

use App\Collection\VersionCollection;
use App\Entity\Version;
use Carbon\Carbon;
use Composer\Package\PackageInterface;
use PHPUnit\Framework\TestCase;

/**
* @covers \App\Collection\VersionCollection
*/
final class VersionCollectionTest extends TestCase
{
public function testSortByReleaseDate(): void
{
$packageA = $this->createMock(PackageInterface::class);
$packageA->method('isDev')->willReturn(false);
$packageA->method('getReleaseDate')->willReturn(Carbon::parse('2020-05-05 12:00:00'));

$packageB = $this->createMock(PackageInterface::class);
$packageB->method('isDev')->willReturn(false);
$packageB->method('getReleaseDate')->willReturn(Carbon::parse('2020-05-10 12:00:00'));

$packageC = $this->createMock(PackageInterface::class);
$packageC->method('isDev')->willReturn(true);
$packageC->method('getReleaseDate')->willReturn(Carbon::parse('2020-05-15 12:00:00'));

$versionA = $this->createMock(Version::class);
$versionA->method('getPackageInformation')->willReturn($packageA);

$versionB = $this->createMock(Version::class);
$versionB->method('getPackageInformation')->willReturn($packageB);

$versionC = $this->createMock(Version::class);
$versionC->method('getPackageInformation')->willReturn($packageC);

$collection = VersionCollection::create(
$versionA,
$versionB,
$versionC,
);

self::assertSame([
$versionB,
$versionA,
$versionC,
], $collection->sortByReleaseDate()->toArray());
}

public function testToMapCollection(): void
{
$packageA = $this->createMock(PackageInterface::class);
$packageA->method('isDev')->willReturn(false);
$packageA->method('getReleaseDate')->willReturn(Carbon::parse('2020-05-05 12:00:00'));

$packageB = $this->createMock(PackageInterface::class);
$packageB->method('isDev')->willReturn(false);
$packageB->method('getReleaseDate')->willReturn(Carbon::parse('2020-05-10 12:00:00'));

$packageC = $this->createMock(PackageInterface::class);
$packageC->method('isDev')->willReturn(true);
$packageC->method('getReleaseDate')->willReturn(Carbon::parse('2020-05-15 12:00:00'));

$versionA = $this->createMock(Version::class);
$versionA->method('getPackageInformation')->willReturn($packageA);

$versionB = $this->createMock(Version::class);
$versionB->method('getPackageInformation')->willReturn($packageB);

$versionC = $this->createMock(Version::class);
$versionC->method('getPackageInformation')->willReturn($packageC);

$collection = VersionCollection::create(
$versionA,
$versionB,
$versionC,
);

self::assertSame([
$packageA,
$packageB,
$packageC,
], $collection->toPackageCollection()->toArray());
}
}

0 comments on commit bfb2ccf

Please sign in to comment.