11<?php
22/**
3- * Copyright © Magento, Inc. All rights reserved.
4- * See COPYING.txt for license details .
3+ * Copyright 2012 Adobe
4+ * All Rights Reserved .
55 */
66declare (strict_types=1 );
77
1515use Magento \Framework \DB \SelectFactory ;
1616use Magento \Framework \Model \ResourceModel \Type \Db \Pdo \Mysql ;
1717use Magento \Framework \Serialize \SerializerInterface ;
18+ use Magento \Framework \Setup \Declaration \Schema \Dto \Factories \Table as DtoFactoriesTable ;
1819use Magento \Framework \Setup \SchemaListener ;
1920use Magento \Framework \Stdlib \DateTime ;
2021use Magento \Framework \Stdlib \StringUtils ;
@@ -55,6 +56,11 @@ class MysqlTest extends TestCase
5556 */
5657 private $ connection ;
5758
59+ /**
60+ * @var LoggerInterface|MockObject
61+ */
62+ private $ logger ;
63+
5864 /**
5965 * Setup
6066 */
@@ -741,10 +747,11 @@ private function getMysqlPdoAdapterMock(array $methods): MockObject
741747
742748 $ string = $ this ->createMock (StringUtils::class);
743749 $ dateTime = $ this ->createMock (DateTime::class);
744- $ logger = $ this ->getMockForAbstractClass (LoggerInterface::class);
750+ $ this -> logger = $ this ->createMock (LoggerInterface::class);
745751 $ selectFactory = $ this ->getMockBuilder (SelectFactory::class)
746752 ->disableOriginalConstructor ()
747753 ->getMock ();
754+ $ dtoFactoriesTable = $ this ->createMock (DtoFactoriesTable::class);
748755
749756 $ adapterMock = $ this ->getMockBuilder (PdoMysqlAdapter::class)
750757 ->onlyMethods (
@@ -753,14 +760,15 @@ private function getMysqlPdoAdapterMock(array $methods): MockObject
753760 [
754761 'string ' => $ string ,
755762 'dateTime ' => $ dateTime ,
756- 'logger ' => $ logger ,
763+ 'logger ' => $ this -> logger ,
757764 'selectFactory ' => $ selectFactory ,
758765 'config ' => [
759766 'dbname ' => 'not_exists ' ,
760767 'username ' => 'not_valid ' ,
761768 'password ' => 'not_valid ' ,
762769 ],
763770 'serializer ' => $ this ->serializerMock ,
771+ 'dtoFactoriesTable ' => $ dtoFactoriesTable ,
764772 ]
765773 )
766774 ->getMock ();
@@ -1067,4 +1075,15 @@ public static function exceptionDataProvider(): array
10671075 [new \Exception ()],
10681076 ];
10691077 }
1078+
1079+ public function testDestruct (): void
1080+ {
1081+ $ adapter = $ this ->getMysqlPdoAdapterMock (['_connect ' , '_rollBack ' ]);
1082+ $ this ->addConnectionMock ($ adapter );
1083+ $ adapter ->expects ($ this ->once ())->method ('_rollBack ' );
1084+ $ this ->logger ->expects ($ this ->once ())->method ('log ' );
1085+ $ adapter ->beginTransaction ();
1086+ $ adapter ->__destruct ();
1087+ $ this ->assertEquals (0 , $ adapter ->getTransactionLevel ());
1088+ }
10701089}
0 commit comments