apiClient = $this->createMock(EbayInventoryApiClient::class); $this->configRepo = $this->createMock(ArticleTypePlatformConfigRepositoryInterface::class); $this->adapter = new EbayAdapter($this->apiClient, $this->configRepo, 'EBAY_DE'); $articleType = new ArticleType('Notebook'); $platform = new Platform('ebay', 'eBay'); $this->platformConfig = new ArticleTypePlatformConfig($articleType, $platform, '177'); $this->article = new Article($articleType, 'NB-001', 'INV-001', 1, ArticleCondition::Good); $this->article->setEbayTitle('Dell Latitude 5520'); $this->article->setListingPrice('299.00'); } public function testGetTypeReturnsEbay(): void { $this->assertSame('ebay', $this->adapter->getType()); } public function testPublishListingCallsUpsertCreateAndPublish(): void { $this->configRepo->method('findByArticleTypeAndPlatformType')->willReturn($this->platformConfig); $this->apiClient->expects($this->once())->method('upsertInventoryItem'); $this->apiClient->expects($this->once())->method('createOffer')->willReturn('offer-123'); $this->apiClient->expects($this->once())->method('publishOffer')->with('offer-123')->willReturn('listing-456'); $listingId = $this->adapter->publishListing($this->article); $this->assertSame('listing-456', $listingId); } public function testPublishListingThrowsWhenNoPlatformConfig(): void { $this->configRepo->method('findByArticleTypeAndPlatformType')->willReturn(null); $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('No eBay platform config found for ArticleType'); $this->adapter->publishListing($this->article); } public function testPublishListingIncludesPoliciesWhenSet(): void { $this->platformConfig->setFulfillmentPolicyId('FP-123'); $this->platformConfig->setPaymentPolicyId('PP-456'); $this->platformConfig->setReturnPolicyId('RP-789'); $this->platformConfig->setMerchantLocationKey('WAREHOUSE-1'); $this->configRepo->method('findByArticleTypeAndPlatformType')->willReturn($this->platformConfig); $this->apiClient->expects($this->once())->method('upsertInventoryItem'); $this->apiClient->expects($this->once()) ->method('createOffer') ->with($this->callback(static function (array $body): bool { return isset($body['listingPolicies']['fulfillmentPolicyId']) && 'FP-123' === $body['listingPolicies']['fulfillmentPolicyId'] && 'PP-456' === $body['listingPolicies']['paymentPolicyId'] && 'RP-789' === $body['listingPolicies']['returnPolicyId'] && 'WAREHOUSE-1' === $body['merchantLocationKey']; })) ->willReturn('offer-123'); $this->apiClient->method('publishOffer')->willReturn('listing-456'); $this->adapter->publishListing($this->article); } public function testPublishListingOmitsPoliciesWhenNotSet(): void { $this->configRepo->method('findByArticleTypeAndPlatformType')->willReturn($this->platformConfig); $this->apiClient->expects($this->once())->method('upsertInventoryItem'); $this->apiClient->expects($this->once()) ->method('createOffer') ->with($this->callback(static function (array $body): bool { return !isset($body['listingPolicies']) && !isset($body['merchantLocationKey']); })) ->willReturn('offer-123'); $this->apiClient->method('publishOffer')->willReturn('listing-456'); $this->adapter->publishListing($this->article); } public function testDeactivateListingWithdrawsOffer(): void { $this->article->setEbayListingId('offer-123'); $this->apiClient->expects($this->once())->method('withdrawOffer')->with('offer-123'); $this->adapter->deactivateListing($this->article); } public function testDeactivateListingIsNoopWhenNoListingId(): void { $this->apiClient->expects($this->never())->method('withdrawOffer'); $this->adapter->deactivateListing($this->article); } }