Merged in feature/MAPG-94-introduce-automatic-unit-testing (pull request #146)

Feature/MAPG-94 introduce automatic unit testing
This commit is contained in:
Bence Pőcze 2020-06-24 22:38:36 +00:00
commit 34206cac12
7 changed files with 1853 additions and 6 deletions

15
bitbucket-pipelines.yml Normal file
View File

@ -0,0 +1,15 @@
image: php:7.4.7-cli-buster
pipelines:
default:
- step:
name: Unit Testing
caches:
- composer
artifacts:
- vendor/**
script:
- apt-get update && apt-get install -y unzip
- curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
- composer install
- vendor/bin/phpunit --testdox tests

View File

@ -8,7 +8,9 @@
"symfony/console": "^5.1",
"phpmailer/phpmailer": "^6.1"
},
"require-dev": {},
"require-dev": {
"phpunit/phpunit": "^9"
},
"autoload": {
"psr-4": {
"MapGuesser\\": "src"

1703
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -4,8 +4,8 @@ ENV DEBIAN_FRONTEND noninteractive
# Install Nginx, PHP and further necessary packages
RUN apt update --fix-missing
RUN apt install -y curl git mariadb-client nginx \
php-apcu php-xdebug php7.4-cli php7.4-curl php7.4-fpm php7.4-mbstring php7.4-mysql php7.4-zip
RUN apt install -y curl git unzip mariadb-client nginx \
php-apcu php-xdebug php7.4-cli php7.4-curl php7.4-fpm php7.4-mbstring php7.4-mysql php7.4-zip php7.4-xml
# Configure Nginx with PHP
RUN mkdir -p /run/php

View File

@ -5,7 +5,7 @@ ROOT_DIR=$(dirname $(readlink -f "$0"))/..
. ${ROOT_DIR}/.env
echo "Installing Composer packages..."
(cd ${ROOT_DIR} && composer install)
(cd ${ROOT_DIR} && composer install --no-dev)
echo "Installing Yarn packages..."
(cd ${ROOT_DIR}/public/static && yarn install)

View File

@ -0,0 +1,98 @@
<?php namespace MapGuesser\Tests\Util\Geo;
use MapGuesser\Util\Geo\Bounds;
use MapGuesser\Util\Geo\Position;
use PHPUnit\Framework\TestCase;
final class BoundsTest extends TestCase
{
public function testCanBeCreatedEmpty(): void
{
$bounds = new Bounds();
$this->assertEquals(90.0, $bounds->getSouthLat());
$this->assertEquals(180.0, $bounds->getWestLng());
$this->assertEquals(-90.0, $bounds->getNorthLat());
$this->assertEquals(-180.0, $bounds->getEastLng());
}
public function testCanBeCreatedWithPosition(): void
{
$position = new Position(45.25, 18.12);
$bounds = new Bounds($position);
$this->assertEquals($position->getLat(), $bounds->getSouthLat());
$this->assertEquals($position->getLng(), $bounds->getWestLng());
$this->assertEquals($position->getLat(), $bounds->getNorthLat());
$this->assertEquals($position->getLng(), $bounds->getEastLng());
}
public function testCanBeCreatedDirectly(): void
{
$bounds = Bounds::createDirectly(44.12, 7.33, 50.12, 15.11);
$this->assertEquals(44.12, $bounds->getSouthLat());
$this->assertEquals(7.33, $bounds->getWestLng());
$this->assertEquals(50.12, $bounds->getNorthLat());
$this->assertEquals(15.11, $bounds->getEastLng());
}
public function testExtendingWithOnePositionIsTheSameAsCreatingWithPosition(): void
{
$position = new Position(45.25, 18.12);
$bounds1 = new Bounds();
$bounds1->extend($position);
$bounds2 = new Bounds($position);
$this->assertEquals($bounds1, $bounds2);
}
public function testCanBeExtendedWithTwoPositions(): void
{
$bounds = new Bounds();
$position1 = new Position(45.25, 18.12);
$position2 = new Position(43.15, 19.28);
$bounds->extend($position1);
$bounds->extend($position2);
$this->assertEquals($position2->getLat(), $bounds->getSouthLat());
$this->assertEquals($position1->getLng(), $bounds->getWestLng());
$this->assertEquals($position1->getLat(), $bounds->getNorthLat());
$this->assertEquals($position2->getLng(), $bounds->getEastLng());
$bounds = new Bounds();
$position1 = new Position(43.15, 18.12);
$position2 = new Position(45.25, 19.28);
$bounds->extend($position1);
$bounds->extend($position2);
$this->assertEquals($position1->getLat(), $bounds->getSouthLat());
$this->assertEquals($position1->getLng(), $bounds->getWestLng());
$this->assertEquals($position2->getLat(), $bounds->getNorthLat());
$this->assertEquals($position2->getLng(), $bounds->getEastLng());
}
public function testCanCalculateApproximateArea(): void
{
$bounds = Bounds::createDirectly(44.12, 7.33, 50.12, 15.11);
$this->assertEqualsWithDelta(391766.09, $bounds->calculateApproximateArea(), 0.01);
}
public function testCanBeConvertedToArray(): void
{
$bounds = Bounds::createDirectly(44.12, 7.33, 50.12, 15.11);
$this->assertEquals(
['south' => 44.12, 'west' => 7.33, 'north' => 50.12, 'east' => 15.11],
$bounds->toArray()
);
}
}

View File

@ -0,0 +1,33 @@
<?php namespace MapGuesser\Tests\Util\Geo;
use MapGuesser\Util\Geo\Position;
use PHPUnit\Framework\TestCase;
final class PositionTest extends TestCase
{
public function testCanBeCreatedWithLatAndLng(): void
{
$position = new Position(45.25, 18.12);
$this->assertEquals(45.25, $position->getLat());
$this->assertEquals(18.12, $position->getLng());
}
public function testCanCalculateDistanceToAnotherPosition(): void
{
$position1 = new Position(44.12, 7.33);
$position2 = new Position(50.12, 15.11);
$this->assertEqualsWithDelta(888785.73, $position1->calculateDistanceTo($position2), 0.01);
}
public function testCanBeConvertedToArray(): void
{
$position = new Position(45.25, 18.12);
$this->assertEquals(
['lat' => 45.25, 'lng' => 18.12],
$position->toArray()
);
}
}