diff --git a/modules/cart/tests/src/Unit/CartProviderTest.php b/modules/cart/tests/src/Unit/CartProviderTest.php index e93fbbd..eff3f47 100644 --- a/modules/cart/tests/src/Unit/CartProviderTest.php +++ b/modules/cart/tests/src/Unit/CartProviderTest.php @@ -1,24 +1,26 @@ getMockBuilder('Drupal\user\UserInterface'); + $mockAccountBuilder = $this->getMockBuilder(UserInterface::class); $this->anonymousUser = $mockAccountBuilder->getMock(); $this->anonymousUser->expects($this->any()) @@ -85,7 +87,7 @@ class CartProviderTest extends UnitTestCase { ->willReturn(TRUE); $this->anonymousUser->expects($this->any()) ->method('id') - ->willReturn(1); + ->willReturn(0); $this->registeredUser = $mockAccountBuilder->getMock(); $this->registeredUser->expects($this->any()) @@ -99,14 +101,14 @@ class CartProviderTest extends UnitTestCase { ->willReturn(1); // Mock the store entity. - $mockStoreBuilder = $this->getMockBuilder('Drupal\commerce_store\StoreInterface'); + $mockStoreBuilder = $this->getMockBuilder(StoreInterface::class); $this->store = $mockStoreBuilder->getMock(); $this->store->expects($this->any()) ->method('id') ->willReturn(1); // MockBuilder to create mocked instances of the OrderInterface. - $mockOrderBuilder = $this->getMockBuilder('Drupal\commerce_order\OrderInterface'); + $mockOrderBuilder = $this->getMockBuilder(OrderInterface::class); // Some order type string we use to differentiate between carts. $this->firstOrderType = 'default'; @@ -149,12 +151,12 @@ class CartProviderTest extends UnitTestCase { ]; // We need this Builder for the CartSessions that is needed during testing. - $this->mockCartSessionBuilder = $this->getMockBuilder('Drupal\commerce_cart\CartSessionInterface'); + $this->mockCartSessionBuilder = $this->getMockBuilder(CartSessionInterface::class); // Mock the getQuery function in the orderStorage. - $mockQueryBuilder = $this->getMockBuilder('Drupal\Core\Entity\Query\QueryInterface'); + $mockQueryBuilder = $this->getMockBuilder(QueryInterface::class); - // query object that returns no cart ids. + // Query object that returns no cart ids. $queryWithOutOrders = $mockQueryBuilder->getMock(); $queryWithOutOrders->expects($this->any()) ->method('execute') @@ -163,11 +165,14 @@ class CartProviderTest extends UnitTestCase { // Mock the query class that returns cart ids. $queryWithOrders = $mockQueryBuilder->getMock(); $queryWithOrders->expects($this->any()) + ->method('condition') + ->willReturnSelf(); + $queryWithOrders->expects($this->any()) ->method('execute') ->willReturn(array_keys($orders)); // Entity storage mock builders to mock the get and create cart tests. - $mockEntityStorageBuilder = $this->getMockBuilder('Drupal\Core\Entity\EntityStorageInterface'); + $mockEntityStorageBuilder = $this->getMockBuilder(EntityStorageInterface::class); // Create the orderStorage for the createCart tests. $createOrderStorage = $mockEntityStorageBuilder->getMock(); @@ -203,7 +208,7 @@ class CartProviderTest extends UnitTestCase { ->willReturn($orders); // Mock the entityManager for the get and create tests. - $mockEntityManagerBuilder = $this->getMockBuilder('Drupal\Core\Entity\EntityManagerInterface'); + $mockEntityManagerBuilder = $this->getMockBuilder(EntityManagerInterface::class); $this->createEntityManager = $mockEntityManagerBuilder->getMock(); $this->createEntityManager->expects($this->any()) @@ -221,7 +226,7 @@ class CartProviderTest extends UnitTestCase { /** * This test the createCart method in the CartProvider for an anonymous user. * - * @covers CartProvider::createCart() + * @covers ::createCart */ public function testCreateAnonymousUserCartProvider() { @@ -232,11 +237,11 @@ class CartProviderTest extends UnitTestCase { ->willReturn([]); // This is the class we want to test. - $cartProvider = new CartProvider($this->entityManager, $this->anonymousUser, $cartSession); + $cartProvider = new CartProvider($this->createEntityManager, $this->anonymousUser, $cartSession); // Test the createCart method. $cart = $cartProvider->createCart($this->firstOrderType, $this->store, $this->anonymousUser); - $this->assertInstanceOf('OrderInterface', $cart, 'The cart is created for an anonymous user if createCart returns an Order entity.'); + $this->assertInstanceOf(OrderInterface::class, $cart, 'The cart is created for an anonymous user if createCart returns an Order entity.'); // Test recreating the cart again with the createCart method. $cart = $cartProvider->createCart($this->firstOrderType, $this->store, $this->anonymousUser); @@ -246,10 +251,10 @@ class CartProviderTest extends UnitTestCase { /** * This tests the get methods for the CartProvider with an anonymous user. * - * @covers CartProvider::getCart() - * @covers CartProvider::getCartId() - * @covers CartProvider::getCarts() - * @covers CartProvider::getCartIds() + * @covers ::getCart + * @covers ::getCartId + * @covers ::getCarts + * @covers ::getCartIds */ public function testGetAnonymousUserCartProvider() { @@ -264,7 +269,7 @@ class CartProviderTest extends UnitTestCase { // Test the getCart method. $cart = $cartProvider->getCart($this->firstOrderType, $this->store, $this->anonymousUser); - $this->assertInstanceOf('OrderInterface', $cart, 'The cart is found when an order type, store and user is given.'); + $this->assertInstanceOf(OrderInterface::class, $cart, 'The cart is found when an order type, store and user is given.'); // Test the getCartId method. $cart_id = $cartProvider->getCartId($this->firstOrderType, $this->store, $this->anonymousUser); @@ -285,7 +290,7 @@ class CartProviderTest extends UnitTestCase { /** * This test the createCart method in the CartProvider for a registered user. * - * @covers CartProvider::createCart() + * @covers ::createCart */ public function testCreateRegisteredUserCartProvider() { @@ -293,11 +298,11 @@ class CartProviderTest extends UnitTestCase { $cartSession = $this->mockCartSessionBuilder->getMock(); // This is the class we want to test. - $cartProvider = new CartProvider($this->entityManager, $this->registeredUser, $cartSession); + $cartProvider = new CartProvider($this->createEntityManager, $this->registeredUser, $cartSession); // Test the createCart method. $cart = $cartProvider->createCart($this->firstOrderType, $this->store, $this->registeredUser); - $this->assertInstanceOf('OrderInterface', $cart, 'The cart is created for an anonymous user if createCart returns an Order entity.'); + $this->assertInstanceOf(OrderInterface::class, $cart, 'The cart is created for an anonymous user if createCart returns an Order entity.'); // Test recreating the cart again with the createCart method. $cart = $cartProvider->createCart($this->firstOrderType, $this->store, $this->registeredUser); @@ -308,10 +313,10 @@ class CartProviderTest extends UnitTestCase { /** * This tests the get methods for the CartProvider with a registered user. * - * @covers CartProvider::getCart() - * @covers CartProvider::getCartId() - * @covers CartProvider::getCarts() - * @covers CartProvider::getCartIds() + * @covers ::getCart + * @covers ::getCartId + * @covers ::getCarts + * @covers ::getCartIds */ public function testGetRegisteredUserCartProvider() { // Mock cart session to get cart ids.