PluginProbe
Packeta / trunk
Packeta vtrunk
2.3.2 2.3.1 trunk 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 All 56 releases
packeta / tests / Module / Checkout / CurrencySwitcherServiceTest.php

CurrencySwitcherServiceTest.php in Packeta trunk, at tests/Module/Checkout/CurrencySwitcherServiceTest.php

62 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare( strict_types=1 );
4
5 namespace Tests\Module\Checkout;
6
7 use Packetery\Module\Checkout\CurrencySwitcherService;
8 use Packetery\Module\Framework\WpAdapter;
9 use Packetery\Module\ModuleHelper;
10 use PHPUnit\Framework\MockObject\MockObject;
11 use PHPUnit\Framework\TestCase;
12
13 class CurrencySwitcherServiceTest extends TestCase {
14 private WpAdapter|MockObject $wpAdapter;
15 private ModuleHelper|MockObject $moduleHelper;
16 private CurrencySwitcherService $currencySwitcherService;
17
18 private function createCurrencySwitcherServiceMock(): void {
19 $this->wpAdapter = $this->createMock( WpAdapter::class );
20 $this->moduleHelper = $this->createMock( ModuleHelper::class );
21 $this->currencySwitcherService = new CurrencySwitcherService( $this->wpAdapter, $this->moduleHelper );
22 }
23
24 public function testGetConvertedPricePluginActive(): void {
25 $this->createCurrencySwitcherServiceMock();
26
27 $inputPrice = 123.0;
28 $outputPrice = 321.0;
29
30 $this->moduleHelper->expects( $this->once() )
31 ->method( 'isPluginActive' )
32 ->with( 'woocommerce-currency-switcher/index.php' )
33 ->willReturn( true );
34
35 $this->wpAdapter->expects( $this->once() )
36 ->method( 'applyFilters' )
37 ->with( 'woocs_exchange_value', $inputPrice )
38 ->willReturn( $outputPrice );
39
40 $this->assertSame( $outputPrice, $this->currencySwitcherService->getConvertedPrice( $inputPrice ) );
41 }
42
43 public function testGetConvertedPricePluginNotActive(): void {
44 $this->createCurrencySwitcherServiceMock();
45
46 $inputPrice = 123.0;
47 $outputPrice = 321.0;
48
49 $this->moduleHelper->expects( $this->once() )
50 ->method( 'isPluginActive' )
51 ->with( 'woocommerce-currency-switcher/index.php' )
52 ->willReturn( false );
53
54 $this->wpAdapter->expects( $this->once() )
55 ->method( 'applyFilters' )
56 ->with( 'packetery_price', $inputPrice )
57 ->willReturn( $outputPrice );
58
59 $this->assertSame( $outputPrice, $this->currencySwitcherService->getConvertedPrice( $inputPrice ) );
60 }
61 }
62