Commit 5bb92a49 authored by Andy J's avatar Andy J

unit tests

parent 96f249cf
......@@ -20,7 +20,8 @@
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.1",
"phpunit/phpunit": "^4.5 || ^5.0.5",
"phpunit/phpunit-mock-objects": "2.3.0 || ^3.0"
"phpunit/phpunit-mock-objects": "2.3.0 || ^3.0",
"Symfony/Finder": "^3.2"
},
"scripts": {
"test": "phpunit"
......
<?php
class OrderSeed
{
public function refs($limit)
{
$keys = Shop::DB()->executeQuery('SELECT kBestellung as id FROM tbestellung ORDER BY RAND() LIMIT ' . $limit, 2);
return array_map(function($val){ return (int)$val->id; }, $keys);
}
public function create($id)
{
$o = new Bestellung($id);
$o->fuelleBestellung(true, false, false, false);
return $o;
}
}
\ No newline at end of file
<?php
class OrderSeed
{
public function refs($limit)
{
$keys = Shop::DB()->executeQuery('SELECT kBestellung as id FROM tbestellung ORDER BY RAND() LIMIT ' . $limit, 2);
return array_map(function ($val) { return (int)$val->id; }, $keys);
}
public function create($id)
{
$o = new Bestellung($id);
$o->fuelleBestellung(true, false, false, false);
return $o;
}
}
<?php
class AddressTest extends TestCase
{
/**
* @dataProvider addressesProvider
*/
public function testEquals($street, $expected)
{
$extracted = PayPalHelper::extractStreet($street);
$this->assertEquals([$extracted->name, $extracted->number], $expected);
}
public function addressesProvider()
{
return [
['Dorpstraat 2', ['Dorpstraat', '2']],
['Dorpstr. 2', ['Dorpstr.', '2']],
['Laan 1933 2', ['Laan 1933', '2']],
['18 Septemberplein 12', ['18 Septemberplein', '12']],
['Kerkstraat 42-f3', ['Kerkstraat', '42-f3']],
['Kerk straat 2b', ['Kerk straat', '2b']],
['42nd street, 1337a', ['42nd street', '1337a']],
['1e Constantijn Huigensstraat 9b', ['1e Constantijn Huigensstraat', '9b']],
['Maas-Waalweg 15', ['Maas-Waalweg', '15']],
['De Dompelaar 1 B', ['De Dompelaar', '1 B']],
['Kümmersbrucker Straße 2', ['Kümmersbrucker Straße', '2']],
['Friedrichstädter Straße 42-46', ['Friedrichstädter Straße', '42-46']],
['Höhenstraße 5A', ['Höhenstraße', '5A']],
['Saturnusstraat 60-75', ['Saturnusstraat', '60-75']]
];
}
}
\ No newline at end of file
<?php
class AddressTest extends TestCase
{
/**
* @dataProvider addressesProvider
*/
public function testEquals($street, $expected)
{
$extracted = PayPalHelper::extractStreet($street);
$this->assertEquals([$extracted->name, $extracted->number], $expected);
}
public function addressesProvider()
{
return [
['Dorpstraat 2', ['Dorpstraat', '2']],
['Dorpstr. 2', ['Dorpstr.', '2']],
['Laan 1933 2', ['Laan 1933', '2']],
['18 Septemberplein 12', ['18 Septemberplein', '12']],
['Kerkstraat 42-f3', ['Kerkstraat', '42-f3']],
['Kerk straat 2b', ['Kerk straat', '2b']],
['42nd street, 1337a', ['42nd street', '1337a']],
['1e Constantijn Huigensstraat 9b', ['1e Constantijn Huigensstraat', '9b']],
['Maas-Waalweg 15', ['Maas-Waalweg', '15']],
['De Dompelaar 1 B', ['De Dompelaar', '1 B']],
['Kümmersbrucker Straße 2', ['Kümmersbrucker Straße', '2']],
['Friedrichstädter Straße 42-46', ['Friedrichstädter Straße', '42-46']],
['Höhenstraße 5A', ['Höhenstraße', '5A']],
['Saturnusstraat 60-75', ['Saturnusstraat', '60-75']]
];
}
}
......@@ -3,14 +3,14 @@
class BasketTest extends TestCase
{
const LIMIT = 100;
/**
* @dataProvider ordersProvider
*/
public function testEquals($order, $expected)
{
$total = [
round($order->fGesamtsummeNetto, 2),
round($order->fGesamtsummeNetto, 2),
round($order->fGesamtsumme, 2)
];
......@@ -20,17 +20,17 @@ class BasketTest extends TestCase
public function ordersProvider()
{
$data = [];
$seeder = new OrderSeed();
foreach ($seeder->refs(self::LIMIT) as $ref) {
$order = $seeder->create($ref);
$helper = new BestellungHelper($order);
$basket = PayPalHelper::getBasket($helper);
$data[] = [$order, $basket->total];
}
return $data;
}
}
......@@ -13,4 +13,4 @@ require $shopPath . '/includes/globalinclude.php';
require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/PayPal/TestCase.php';
Shop::run();
\ No newline at end of file
Shop::run();
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment