Skip to content

Commit

Permalink
Добавлен метод addFindPartReferences, некоторые тесты
Browse files Browse the repository at this point in the history
Добавлен метод addFindPartReferences , написаны тесты для Query и QueryBuilder, подключен travis для сборки.
  • Loading branch information
shude committed Jan 28, 2020
1 parent acba8e7 commit 3e8152f
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 13 deletions.
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: php

matrix:
include:
- php: 7.2
- php: 7.3
- php: 7.4

before_script:
- composer install

script:
- ./vendor/bin/phpunit --bootstrap vendor/autoload.php Tests
11 changes: 11 additions & 0 deletions Laximo.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use shude\Laximo\Objects\CatalogObject;
use shude\Laximo\Objects\CategoryListObject;
use shude\Laximo\Objects\DetailListObject;
use shude\Laximo\Objects\DetailReferencesListObject;
use shude\Laximo\Objects\FilterObject;
use shude\Laximo\Objects\ImageMapObject;
use shude\Laximo\Objects\UnitListObject;
Expand Down Expand Up @@ -240,6 +241,16 @@ public function addFindApplicableVehicles(string $oem, string $catalog, string $
return $this;
}

public function addFindPartReferences(string $oem)
{
$this->addQuery('FINDPARTREFERENCES',[
'Locale' => $this->locale,
'OEM' => $oem
]);

$this->resultObjectStack[] = DetailReferencesListObject::class;
}

public function execute()
{
$query = $this->queryBuilder->buildQueryString();
Expand Down
5 changes: 0 additions & 5 deletions Objects/DetailReferenceObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,4 @@ protected function fromXml($data)
$this->brand = (string)$data->attributes()->brand;
$this->code = (string)$data->attributes()->code;
}

protected function fromJSON($data) {
$this->brand = (string) $data['catalog']->attributes()->brand;
$this->code = (string)$data['catalog']->attributes()->code;
}
}
11 changes: 3 additions & 8 deletions Objects/DetailReferencesListObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,17 @@ protected function fromXml($data)
foreach ($data->OEMPartReference as $OEMPartReferenceItem) {
foreach ($OEMPartReferenceItem->CatalogReferences as $catalogReference) {
foreach ($catalogReference->CatalogReference as $reference) {
$this->addNewReference($OEMPartReferenceItem, $reference);
$this->addNewReference($reference);
}
}
}
}
}
}

private function addNewReference($OEMPartReferenceItem, $catalogReference)
private function addNewReference($catalogReference)
{
$creationalData = [
'detail' => $OEMPartReferenceItem,
'catalog' => $catalogReference
];

$detailReference = new DetailReferenceObject($creationalData);
$detailReference = new DetailReferenceObject($catalogReference);
$this->referencesList[] = $detailReference;
}
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Laximo API PHP Library
======================
[![Build Status](https://travis-ci.org/shude/laximo.svg?branch=master)](https://travis-ci.org/shude/laximo)
[![Latest Stable Version](https://poser.pugx.org/shude/laximo/v/stable)](https://packagist.org/packages/shude/laximo)
[![Total Downloads](https://poser.pugx.org/shude/laximo/downloads)](https://packagist.org/packages/shude/laximo)
[![License](https://poser.pugx.org/shude/laximo/license)](https://packagist.org/packages/shude/laximo)
Expand Down
49 changes: 49 additions & 0 deletions Tests/Query/QueryBuilderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php


namespace shude\Laximo\Tests\Query;


use PHPUnit\Framework\TestCase;
use shude\Laximo\Query\Query;
use shude\Laximo\Query\QueryBuilder;

final class QueryBuilderTest extends TestCase
{
public function testBuildCorrectQueryStringWithOneQuery()
{
$query = $this->createMock(Query::class);
$query->method('getQueryString')->willReturn('Some command');

$builder = new QueryBuilder();
$builder->addQuery($query);

$this->assertEquals('Some command',$builder->buildQueryString());
}

public function testBuildCorrectQueryStringWithMultiQueries()
{
$query = $this->createMock(Query::class);
$query->method('getQueryString')->will(
$this->onConsecutiveCalls('First', 'Second')
);

$builder = new QueryBuilder();
$builder->addQuery($query);
$builder->addQuery($query);

$this->assertEquals("First\nSecond",$builder->buildQueryString());
}

public function testClearWorksCorrectly()
{
$query = $this->createMock(Query::class);
$query->method('getQueryString')->willReturn('Some command');

$builder = new QueryBuilder();
$builder->addQuery($query);
$builder->clear();

$this->assertEmpty($builder->buildQueryString());
}
}
18 changes: 18 additions & 0 deletions Tests/Query/QueryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php


namespace shude\Laximo\Tests\Query;


use PHPUnit\Framework\TestCase;
use shude\Laximo\Query\Query;

final class QueryTest extends TestCase
{
public function testBuildCorrectQueryString()
{
$query = new Query('test_command',['param1'=>'value1', 'param2' => 'value2']);

$this->assertEquals('test_command:param1=value1|param2=value2', $query->getQueryString());
}
}
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@
"exclude-from-classmap": [
"/Tests/"
]
},
"require-dev": {
"phpunit/phpunit": "^8"
}
}

0 comments on commit 3e8152f

Please sign in to comment.