88
99namespace Propel \Tests \Runtime \TypeTests ;
1010
11+ use PHPUnit \Framework \Attributes \DataProvider ;
1112use Propel \Tests \Bookstore \Map \TypeObjectTableMap ;
13+ use Propel \Tests \Bookstore \TypeNumeric ;
14+ use Propel \Tests \Bookstore \TypeNumericQuery ;
1215use Propel \Tests \Bookstore \TypeObject ;
1316use Propel \Tests \Bookstore \TypeObjectQuery ;
1417use Propel \Tests \Helpers \Bookstore \BookstoreTestBase ;
1518use Propel \Tests \Runtime \TypeTests \DummyObjectClass ;
16- use Propel \Tests \Runtime \TypeTests \TypeObjectInterface ;
1719use ReflectionClass ;
1820
1921/**
22+ * NOTE: Uses classes from bookstore/types-schema.xml.
23+ *
2024 * @group database
2125 */
2226class TypeTest extends BookstoreTestBase
2327{
28+ public static function setUpBeforeClass (): void
29+ {
30+ parent ::setUpBeforeClass ();
31+ TypeNumericQuery::create ()->deleteAll ();
32+ }
33+
2434 /**
2535 * @return void
2636 */
@@ -47,20 +57,6 @@ public function testTypeHintArray()
4757 $ this ->assertTrue ($ param ->allowsNull ());
4858 }
4959
50- /**
51- * @return void
52- */
53- public function testInterface ()
54- {
55- $ this ->markTestSkipped ('Setting interface on fk-relations was removed ' );
56- $ reflection = new ReflectionClass (TypeObject::class);
57- $ method = $ reflection ->getMethod ('setTypeObject ' );
58- $ param = $ method ->getParameters ()[0 ];
59-
60- $ this ->assertEquals (TypeObjectInterface::class, $ param ->getType ()->getName ());
61- $ this ->assertTrue ($ param ->allowsNull ());
62- }
63-
6460 /**
6561 * @return void
6662 */
@@ -128,4 +124,34 @@ public function testObjectType()
128124
129125 $ this ->assertEquals ($ q , $ typeObjectEntity ->getDetails ());
130126 }
127+
128+ public static function DecimalValuesDataProvider (): array
129+ {
130+ $ values = [ // string $inputValue, string $storedValue
131+ ['12345.333 ' , '12345.3330 ' ],
132+ ['12345 ' , '12345.0000 ' ],
133+ ];
134+
135+ return [ // string $columnName, string $inputValue, string $storedValue
136+ ...array_map (fn ($ dataSet ) => ['Decimal ' , ...$ dataSet ], $ values ),
137+ ...array_map (fn ($ dataSet ) => ['Numeric ' , ...$ dataSet ], $ values ),
138+ ];
139+ }
140+
141+ #[DataProvider('DecimalValuesDataProvider ' )]
142+ public function testDecimalType (string $ columnName , string $ inputValue , string $ storedValue ): void
143+ {
144+ if (static ::runningOnSQLite ()) {
145+ $ this ->markTestSkipped ('Sqlite stores decimals as strings. ' );
146+ }
147+
148+ $ o = new TypeNumeric ();
149+ $ o ->setByName ($ columnName , $ inputValue )->save ();
150+
151+ $ o ->reload ();
152+ $ this ->assertSame ($ storedValue , $ o ->getByName ($ columnName ));
153+
154+ $ foundValue = TypeNumericQuery::create ()->filterBy ($ columnName , $ storedValue )->findOne ();
155+ $ this ->assertSame ($ o , $ foundValue );
156+ }
131157}
0 commit comments