Skip to content

Commit

Permalink
Merge 458da1d into 78c45a7
Browse files Browse the repository at this point in the history
  • Loading branch information
diegofelix committed Jul 16, 2018
2 parents 78c45a7 + 458da1d commit 51dedb6
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 18 deletions.
5 changes: 1 addition & 4 deletions src/AbstractFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ public function useProduction(): self

public function newFeed(string $name, bool $incremental = false): FeedElementInterface
{
$feedElement = new FeedElement($name, $incremental);
$feedElement->setNamespace($this->getNamespace());

return $feedElement;
return new FeedElement($name, $incremental);
}

public function printFeed(FeedElementInterface $feed): string
Expand Down
24 changes: 16 additions & 8 deletions src/Elements/FeedElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,8 @@ public function addCategories(array $categories): FeedElementInterface

public function generateXMLArray(): array
{
$xmlNamespace = 'http://www.bazaarvoice.com/xs/PRR/'.$this->namespace.'/'.self::$apiVersion;

$element = [
'#attributes' => [
'xmlns' => $xmlNamespace,
'name' => $this->name,
'incremental' => $this->incremental ? 'true' : 'false',
'extractDate' => date('Y-m-d\TH:i:s'),
],
'#attributes' => $this->getBasicXmlAttributes(),
];

if ($brands = $this->generateBrandsXMLArray()) {
Expand Down Expand Up @@ -188,6 +181,21 @@ public function generateProductsXMLArray(): array
return $element;
}

public function getBasicXmlAttributes(): array
{
return [
'xmlns' => $this->getNamespace(),
'name' => $this->name,
'incremental' => $this->incremental ? 'true' : 'false',
'extractDate' => date('Y-m-d\TH:i:s'),
];
}

public function getNamespace(): string
{
return 'http://www.bazaarvoice.com/xs/PRR/ProductFeed/'.self::$apiVersion;
}

private function generateInteractionsXMLArray(): array
{
if (!count($this->interactions)) {
Expand Down
4 changes: 4 additions & 0 deletions src/Elements/FeedElementInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ public function addCategories(array $categories): FeedElementInterface;
public function addInteraction(InteractionElement $interaction): FeedElementInterface;

public function addBrands(array $brands): FeedElementInterface;

public function getBasicXmlAttributes(): array;

public function getNamespace(): string;
}
15 changes: 15 additions & 0 deletions src/Elements/InteractionFeedElement.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
namespace BazaarVoice\Elements;

class InteractionFeedElement extends FeedElement implements FeedElementInterface
{
public function getBasicXmlAttributes(): array
{
return ['xmlns' => $this->getNamespace()];
}

public function getNamespace(): string
{
return 'http://www.bazaarvoice.com/xs/PRR/PostPurchaseFeed/'.self::$apiVersion;
}
}
2 changes: 0 additions & 2 deletions src/FeedInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ interface FeedInterface
{
public function newFeed(string $name, bool $incremental = false): FeedElementInterface;

public function getNamespace(): string;

public function printFeed(FeedElementInterface $feed): string;

public function saveFeed(FeedElementInterface $feed, string $fileLocation, string $fileName);
Expand Down
6 changes: 4 additions & 2 deletions src/Interaction/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

use BazaarVoice\AbstractFeed;
use BazaarVoice\Elements\InteractionElement;
use BazaarVoice\Elements\FeedElementInterface;
use BazaarVoice\Elements\InteractionFeedElement;
use BazaarVoice\FeedInterface;

class Feed extends AbstractFeed implements FeedInterface
Expand All @@ -25,8 +27,8 @@ public function newInteraction(
);
}

public function getNamespace(): string
public function newFeed(string $name, bool $incremental = false): FeedElementInterface
{
return 'PostPurchaseFeed';
return new InteractionFeedElement($name, $incremental);
}
}
2 changes: 1 addition & 1 deletion tests/Feature/FeedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function it_generates_an_interaction_feed()
$result = $feed->printFeed($element);

// Assertions
$this->assertFeedXmlWasGeneratedCorrectly($expectedFeed, $result);
$this->assertXmlStringEqualsXmlString($expectedFeed, $result);
}

/** @test */
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/interaction-feed.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Feed xmlns="http://www.bazaarvoice.com/xs/PRR/PostPurchaseFeed/5.6" name="InteractionFeed" incremental="false" extractDate="2018-07-12T14:28:52">
<Feed xmlns="http://www.bazaarvoice.com/xs/PRR/PostPurchaseFeed/5.6">
<Interaction>
<TransactionDate>22/03/1987</TransactionDate>
<EmailAddress>john@doe.com</EmailAddress>
Expand Down

0 comments on commit 51dedb6

Please sign in to comment.