woocommerce-paypal-payments/tests/PHPUnit/ApiClient/Entity/ItemTest.php

92 lines
2.3 KiB
PHP
Raw Normal View History

2020-08-31 13:38:54 +03:00
<?php
declare(strict_types=1);
2020-09-14 07:51:45 +03:00
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
2020-08-31 13:38:54 +03:00
2022-02-09 16:28:27 +02:00
use WooCommerce\PayPalCommerce\TestCase;
2020-08-31 13:38:54 +03:00
use Mockery;
class ItemTest extends TestCase
{
public function test()
{
$unitAmount = Mockery::mock(Money::class);
$tax = Mockery::mock(Money::class);
$testee = new Item(
'name',
$unitAmount,
1,
'description',
$tax,
'sku',
'PHYSICAL_GOODS'
);
$this->assertEquals('name', $testee->name());
2020-09-01 09:47:36 +03:00
$this->assertEquals($unitAmount, $testee->unit_amount());
2020-08-31 13:38:54 +03:00
$this->assertEquals(1, $testee->quantity());
$this->assertEquals('description', $testee->description());
$this->assertEquals($tax, $testee->tax());
$this->assertEquals('sku', $testee->sku());
$this->assertEquals('PHYSICAL_GOODS', $testee->category());
}
public function testDigitalGoodsCategory()
{
$unitAmount = Mockery::mock(Money::class);
$tax = Mockery::mock(Money::class);
$testee = new Item(
'name',
$unitAmount,
1,
'description',
$tax,
'sku',
'DIGITAL_GOODS'
);
$this->assertEquals('DIGITAL_GOODS', $testee->category());
}
public function testToArray()
{
$unitAmount = Mockery::mock(Money::class);
$unitAmount
2020-09-01 09:47:36 +03:00
->expects('to_array')
2020-08-31 13:38:54 +03:00
->andReturn([1]);
$tax = Mockery::mock(Money::class);
$tax
2020-09-01 09:47:36 +03:00
->expects('to_array')
2020-08-31 13:38:54 +03:00
->andReturn([2]);
2023-09-20 17:43:29 +04:00
$image_url = 'https://example.com/wp-content/uploads/2023/06/beanie-2.jpg';
2020-08-31 13:38:54 +03:00
$testee = new Item(
'name',
$unitAmount,
1,
'description',
$tax,
'sku',
2023-08-31 17:40:06 +04:00
'PHYSICAL_GOODS',
'url',
2023-09-20 17:43:29 +04:00
$image_url
2020-08-31 13:38:54 +03:00
);
$expected = [
'name' => 'name',
'unit_amount' => [1],
'quantity' => 1,
'description' => 'description',
'sku' => 'sku',
'category' => 'PHYSICAL_GOODS',
2023-08-31 17:40:06 +04:00
'url' => 'url',
2023-09-20 17:43:29 +04:00
'image_url' => $image_url,
2020-08-31 13:38:54 +03:00
'tax' => [2],
];
2020-09-01 09:47:36 +03:00
$this->assertEquals($expected, $testee->to_array());
2020-08-31 13:38:54 +03:00
}
}