|
4 | 4 |
|
5 | 5 | namespace Yiisoft\ActiveRecord\Tests; |
6 | 6 |
|
7 | | -use ArgumentCountError; |
8 | 7 | use DivisionByZeroError; |
9 | 8 | use InvalidArgumentException; |
10 | 9 | use LogicException; |
|
32 | 31 | use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\Order; |
33 | 32 | use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\OrderItem; |
34 | 33 | use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\OrderItemWithNullFK; |
| 34 | +use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\OrderWithConstructor; |
35 | 35 | use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\OrderWithFactory; |
36 | 36 | use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\Profile; |
37 | 37 | use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\Promotion; |
@@ -1069,10 +1069,9 @@ public function testWithFactoryNonInitiated(): void |
1069 | 1069 |
|
1070 | 1070 | $this->assertInstanceOf(Customer::class, $customer); |
1071 | 1071 |
|
1072 | | - $this->expectException(ArgumentCountError::class); |
1073 | | - $this->expectExceptionMessage('Too few arguments to function'); |
1074 | | - |
1075 | 1072 | $customer = $order->getCustomerWithFactory(); |
| 1073 | + |
| 1074 | + $this->assertInstanceOf(Customer::class, $customer); |
1076 | 1075 | } |
1077 | 1076 |
|
1078 | 1077 | public function testSerialization(): void |
@@ -1939,5 +1938,42 @@ public function testGetAllWithHasOneAndArrayValue(): void |
1939 | 1938 | $this->assertNull($promotions[1]->relation('singleItem')); |
1940 | 1939 | } |
1941 | 1940 |
|
| 1941 | + public function testWithConstructorQuery(): void |
| 1942 | + { |
| 1943 | + /** @var OrderWithConstructor[] $orders */ |
| 1944 | + $orders = OrderWithConstructor::query()->all(); |
| 1945 | + |
| 1946 | + $this->assertCount(3, $orders); |
| 1947 | + } |
| 1948 | + |
| 1949 | + public function testWithConstructorRelations(): void |
| 1950 | + { |
| 1951 | + $orderItems = OrderWithConstructor::query()->findByPk(1)->getOrderItems(); |
| 1952 | + $this->assertCount(2, $orderItems); |
| 1953 | + } |
| 1954 | + |
| 1955 | + public function testWithConstructorRepositoryTrait(): void |
| 1956 | + { |
| 1957 | + $this->assertCount(3, OrderWithConstructor::findAll()); |
| 1958 | + $this->assertInstanceOf(OrderWithConstructor::class, OrderWithConstructor::findByPk(1)); |
| 1959 | + } |
| 1960 | + |
| 1961 | + public function testWithConstructorNewInstance(): void |
| 1962 | + { |
| 1963 | + $this->reloadFixtureAfterTest(); |
| 1964 | + |
| 1965 | + $newOrder = new OrderWithConstructor(1); |
| 1966 | + |
| 1967 | + $this->assertTrue($newOrder->isNew()); |
| 1968 | + $newOrder->save(); |
| 1969 | + $this->assertFalse($newOrder->isNew()); |
| 1970 | + $this->assertSame(4, $newOrder->getId()); |
| 1971 | + $this->assertNotNull($newOrder->getCreatedAt()); |
| 1972 | + $this->assertNotNull($newOrder->getUpdatedAt()); |
| 1973 | + $this->assertNull($newOrder->getDeletedAt()); |
| 1974 | + $this->assertSame(1, $newOrder->delete()); |
| 1975 | + $this->assertNotNull($newOrder->getDeletedAt()); |
| 1976 | + } |
| 1977 | + |
1942 | 1978 | abstract protected function createFactory(): Factory; |
1943 | 1979 | } |
0 commit comments