From cb067ccb77b7b079fc9600a7d4e96d8f551fec51 Mon Sep 17 00:00:00 2001 From: Joel Male Date: Sat, 11 Apr 2026 08:17:47 +1000 Subject: [PATCH] test: fix quality issues and expand coverage for namespaced fields, empty feed, xml declaration --- tests/LaravelGoogleShoppingFeedTest.php | 37 +++++++++++++++++++++---- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/tests/LaravelGoogleShoppingFeedTest.php b/tests/LaravelGoogleShoppingFeedTest.php index af99f1b..558a8bd 100644 --- a/tests/LaravelGoogleShoppingFeedTest.php +++ b/tests/LaravelGoogleShoppingFeedTest.php @@ -36,10 +36,10 @@ function validProduct(array $overrides = []): array describe('addItem', function () { it('accepts a valid item without throwing', function () { - $feed = LaravelGoogleShoppingFeed::init(); + $feed = LaravelGoogleShoppingFeed::init('', '', ''); $feed->addItem(validProduct()); - expect(true)->toBeTrue(); + expect($feed)->toBeInstanceOf(LaravelGoogleShoppingFeed::class); }); it('throws for missing required field', function (string $field) { @@ -63,7 +63,7 @@ function validProduct(array $overrides = []): array it('returns a string', function () { $feed = LaravelGoogleShoppingFeed::init('Store', 'Desc', 'https://example.com'); - expect(is_string($feed->toXml()))->toBeTrue(); + expect($feed->toXml())->toBeString(); }); it('contains the RSS xmlns:g attribute', function () { @@ -85,9 +85,9 @@ function validProduct(array $overrides = []): array $xml = $feed->toXml(); expect($xml) - ->toContain('My Store') - ->toContain('My Description') - ->toContain('https://example.com'); + ->toContain('My Store') + ->toContain('My Description') + ->toContain('https://example.com'); }); it('includes product data', function () { @@ -120,6 +120,31 @@ function validProduct(array $overrides = []): array ->and($xml)->toContain('prod-1') ->and($xml)->toContain('prod-2'); }); + + it('includes namespaced google fields in output', function () { + $feed = LaravelGoogleShoppingFeed::init('', '', ''); + $feed->addItem(validProduct()); + $xml = $feed->toXml(); + + expect($xml) + ->toContain('29.99 AUD') + ->toContain('https://example.com/image.jpg'); + }); + + it('generates valid xml with no products', function () { + $feed = LaravelGoogleShoppingFeed::init('My Store', 'My Desc', 'https://example.com'); + $xml = $feed->toXml(); + + expect($xml) + ->toBeString() + ->toContain('My Store') + ->not->toContain(''); + }); + + it('includes the xml declaration', function () { + $feed = LaravelGoogleShoppingFeed::init('', '', ''); + expect($feed->toXml())->toStartWith('