Skip to content

Commit 300cdce

Browse files
committed
Added some tests
1 parent c4ab0ec commit 300cdce

File tree

7 files changed

+234
-5
lines changed

7 files changed

+234
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.idea/
2+
.phpunit.result.cache
23
composer.lock
34
vendor/

.travis.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
language: php
2+
3+
sudo: false
4+
5+
php:
6+
- 7.2
7+
- 7.3
8+
9+
cache:
10+
directories:
11+
- vendor
12+
13+
install:
14+
- composer install --prefer-dist --no-interaction --no-scripts
15+
16+
script: vendor/bin/phpunit

Model/ComplexDefinition.php

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,49 @@
99
*/
1010
class ComplexDefinition
1111
{
12+
/** @var integer */
13+
protected $complexDefinitionId;
14+
15+
/** @var string */
16+
protected $code;
17+
1218
/**
13-
* @var integer
19+
* @return int
1420
*/
15-
protected $complexDefinitionId;
21+
public function getComplexDefinitionId()
22+
{
23+
return $this->complexDefinitionId;
24+
}
1625

1726
/**
18-
* @var string
27+
* @param int $complexDefinitionId
28+
*
29+
* @return ComplexDefinition
1930
*/
20-
protected $code;
21-
}
31+
public function setComplexDefinitionId($complexDefinitionId)
32+
{
33+
$this->complexDefinitionId = $complexDefinitionId;
34+
35+
return $this;
36+
}
37+
38+
/**
39+
* @return string
40+
*/
41+
public function getCode()
42+
{
43+
return $this->code;
44+
}
45+
46+
/**
47+
* @param string $code
48+
*
49+
* @return ComplexDefinition
50+
*/
51+
public function setCode($code)
52+
{
53+
$this->code = $code;
54+
55+
return $this;
56+
}
57+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
namespace Jstack\Newyse\Tests\Criteria;
4+
5+
use Jstack\Newyse\Criteria\ReservationCriteria;
6+
use Jstack\Newyse\Reservation\Preference;
7+
use Jstack\Newyse\Reservation\SubjectQuantity;
8+
use PHPUnit\Framework\TestCase;
9+
10+
class ReservationCriteriaTest extends TestCase
11+
{
12+
public function testToRequest()
13+
{
14+
$preference = new Preference();
15+
$preference->setId(123);
16+
$preference->setType('SomeType');
17+
18+
$subject = new SubjectQuantity();
19+
$subject->setQuantity(2);
20+
$subject->setSubjectId(1);
21+
22+
$reservationCriteria = new ReservationCriteria();
23+
$reservationCriteria->setResourceId(1);
24+
$reservationCriteria->setArrivalDate('2019-01-01');
25+
$reservationCriteria->setDuration(3);
26+
$reservationCriteria->setPreferences([$preference]);
27+
$reservationCriteria->setLanguage('nl');
28+
$reservationCriteria->setCustomerId(1234);
29+
$reservationCriteria->setRemark('Some remarks');
30+
$reservationCriteria->setSubjects([$subject]);
31+
32+
$expected = [
33+
'ReservationCategoryCode' => 'res',
34+
'Accommodation' => [
35+
'ResourceId' => 1,
36+
'ArrivalDate' => '2019-01-01',
37+
'Duration' => 3,
38+
'SpecialCode' => null,
39+
],
40+
'Preferences' => [
41+
['Id' => 123, 'Type' => 'SomeType']
42+
],
43+
'Language' => 'nl',
44+
'SubjectQuantities' => [
45+
['SubjectId' => 1, 'Quantity' => 2]
46+
],
47+
'CustomerId' => 1234,
48+
'Remark' => 'Some remarks',
49+
'Voucher' => null,
50+
'SourceCode' => null,
51+
'SendMethodCode' => null,
52+
'Additions' => [],
53+
'ReturnBill' => true,
54+
'ReturnInstalments' => null,
55+
'ReturnTermsAndConditions' => null,
56+
'SendEmail' => null,
57+
];
58+
59+
$this->assertEquals($expected, $reservationCriteria->getRequest());
60+
}
61+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
3+
namespace Jstack\Newyse\Tests\Mapper;
4+
5+
use Jstack\Newyse\Mapper\ResponseMapper;
6+
use Jstack\Newyse\Model\AccommodationType;
7+
use Jstack\Newyse\Model\Availability;
8+
use Jstack\Newyse\Model\Property;
9+
use PHPUnit\Framework\TestCase;
10+
11+
class ResponseMapperTest extends TestCase
12+
{
13+
public function testMapSimpleProperties()
14+
{
15+
$accommodationTypeDefinition = [
16+
'ResourceId' => 4,
17+
'Code' => 'SomeCode'
18+
];
19+
20+
$responseMapper = new ResponseMapper();
21+
$accommodationType = $responseMapper->map($accommodationTypeDefinition, new AccommodationType());
22+
23+
$this->assertEquals(4, $accommodationType->getResourceId());
24+
$this->assertEquals('SomeCode', $accommodationType->getCode());
25+
}
26+
27+
public function testMapOneToManyRelations()
28+
{
29+
$availabilityDefinition = [
30+
'Prices' => (object) [
31+
'PriceItem' => [
32+
['Price' => 1000],
33+
['Price' => 2000]
34+
]
35+
]
36+
];
37+
38+
$responseMapper = new ResponseMapper();
39+
$availability = $responseMapper->map($availabilityDefinition, new Availability());
40+
41+
$this->assertEquals(2000, $availability->getPrices()[1]->getPrice());
42+
}
43+
44+
public function testMapOneToManyRelationsWithOnlyOneChild()
45+
{
46+
$availabilityDefinition = [
47+
'Prices' => (object) [
48+
'PriceItem' => (object) ['Price' => 1000]
49+
]
50+
];
51+
52+
$responseMapper = new ResponseMapper();
53+
$availability = $responseMapper->map($availabilityDefinition, new Availability());
54+
55+
$this->assertEquals(1000, $availability->getPrices()[0]->getPrice());
56+
}
57+
58+
public function testMapOneToOneRelations()
59+
{
60+
$accommodationTypeDefinition = [
61+
'ComplexDefinition' => (object) [
62+
'Code' => 'Some Code',
63+
'ComplexDefinitionId' => 123
64+
]
65+
];
66+
67+
$responseMapper = new ResponseMapper();
68+
$accommodationType = $responseMapper->map($accommodationTypeDefinition, new AccommodationType());
69+
70+
$this->assertEquals('Some Code', $accommodationType->getComplexDefinition()->getCode());
71+
}
72+
73+
public function testMapDateTime()
74+
{
75+
$propertyDefinition = [
76+
'StartDate' => '2019-01-01 12:00:00'
77+
];
78+
79+
$responseMapper = new ResponseMapper();
80+
$property = $responseMapper->map($propertyDefinition, new Property());
81+
82+
$this->assertSame('2019-01-01 12:00:00', $property->getStartDate()->format('Y-m-d H:i:s'));
83+
}
84+
85+
public function testMapArray()
86+
{
87+
$array = [
88+
['ResourceId' => 4, 'Code' => 'Code1'],
89+
['ResourceId' => 6, 'Code' => 'Code2']
90+
];
91+
92+
$responseMapper = new ResponseMapper();
93+
$accommodationTypes = $responseMapper->mapArray($array, new AccommodationType());
94+
95+
$this->assertSame('Code2', $accommodationTypes[1]->getCode());
96+
}
97+
}

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,8 @@
1717
"psr-4": {
1818
"Jstack\\Newyse\\": "."
1919
}
20+
},
21+
"require-dev": {
22+
"phpunit/phpunit": "^8.3"
2023
}
2124
}

phpunit.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<phpunit
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.2/phpunit.xsd"
6+
backupGlobals="false"
7+
colors="true"
8+
bootstrap="vendor/autoload.php"
9+
>
10+
<testsuites>
11+
<testsuite name="Project Test Suite">
12+
<directory>Tests</directory>
13+
</testsuite>
14+
</testsuites>
15+
</phpunit>

0 commit comments

Comments
 (0)