Skip to content

Commit

Permalink
REENG-251 Fix for null spot
Browse files Browse the repository at this point in the history
  • Loading branch information
michalblocinski authored and dzmitrybitsiutski committed May 17, 2024
1 parent cf50bff commit 864df5e
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## 2.7.2
- Initializing spots with empty array in location

## 2.7.1
- Added encoding spot to location

Expand Down
2 changes: 1 addition & 1 deletion src/Paysera/WalletApi/Entity/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class Paysera_WalletApi_Entity_Location
/**
* @var Paysera_WalletApi_Entity_Spot[]
*/
private $spots;
private $spots = array();

/**
* Set id
Expand Down
78 changes: 78 additions & 0 deletions tests/Paysera/WalletApi/MapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1877,6 +1877,84 @@ public function testEncodeLocation() {
$this->assertEquals($expectedData, $encodedLocation);
}

public function testEncodeLocationEmptySpot() {
$location = new Paysera_WalletApi_Entity_Location();
$location->setId(1);
$location->setTitle('Test Location');
$location->setDescription('This is a test location');
$location->setAddress('Test Address');
$location->setRadius(100);
$location->setLat(54.6872);
$location->setLng(25.2797);

$price1 = new Paysera_WalletApi_Entity_Location_Price();
$price1->setTitle('a');
$price1->markAsPrice();
$price1->setPrice(new Paysera_WalletApi_Entity_Money(10000, 'EUR'));
$location->addPrice($price1);

$price2 = new Paysera_WalletApi_Entity_Location_Price();
$price2->setTitle('b');
$price2->markAsPrice();
$price2->setPrice(new Paysera_WalletApi_Entity_Money(20000, 'USD'));
$location->addPrice($price2);

$openingTime = new Paysera_WalletApi_Entity_Time('9', '0');
$closingTime = new Paysera_WalletApi_Entity_Time('17', '0');
$workingHours1 = new Paysera_WalletApi_Entity_Location_DayWorkingHours();
$workingHours1->markAsMonday();
$workingHours1->setOpeningTime($openingTime);
$workingHours1->setClosingTime($closingTime);
$location->addWorkingHours($workingHours1);

$workingHours2 = new Paysera_WalletApi_Entity_Location_DayWorkingHours();
$workingHours2->markAsTuesday();
$workingHours2->setOpeningTime($openingTime);
$workingHours2->setClosingTime($closingTime);
$location->addWorkingHours($workingHours2);

$location->setImagePinOpen('http://example.com/pin_open.png');
$location->setImagePinClosed('http://example.com/pin_closed.png');

$location->setServices([
'pay',
'cash_in',
'cash_out',
]);

$location->setStatus('active');
$location->setPublic(true);

$encodedLocation = $this->mapper->encodeLocation($location);

$expectedData = [
'id' => 1,
'title' => 'Test Location',
'description' => 'This is a test location',
'address' => 'Test Address',
'radius' => 100,
'lat' => 54.6872,
'lng' => 25.2797,
'prices' => [
['title' => 'a', 'type' => 'price', 'price' => ['amount' => 1000000, 'currency' => 'EUR']],
['title' => 'b', 'type' => 'price', 'price' => ['amount' => 2000000, 'currency' => 'USD']]
],
'working_hours' => [
'monday' => ['opening_time' => '9:0', 'closing_time' => '17:0'],
'tuesday' => ['opening_time' => '9:0', 'closing_time' => '17:0']
],
'services' => [
'pay' => ['available' => true],
'cash_in' => ['available' => true],
'cash_out' => ['available' => true]
],
'status' => 'active',
'public' => true,
'spots' => [],
];
$this->assertEquals($expectedData, $encodedLocation);
}

private function setProperty($object, $property, $value)
{
$reflectionProperty = new ReflectionProperty($object, $property);
Expand Down

0 comments on commit 864df5e

Please sign in to comment.