File tree Expand file tree Collapse file tree 2 files changed +66
-0
lines changed Expand file tree Collapse file tree 2 files changed +66
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace MongoDB \Laravel \Tests \Models ;
6+
7+ use MongoDB \Laravel \Eloquent \Model as Eloquent ;
8+ use MongoDB \Laravel \Query \Builder ;
9+
10+ /**
11+ * @property string $name
12+ * @property string $country
13+ * @property bool $can_be_eaten
14+ * @mixin Eloquent
15+ * @method static Builder create(...$values)
16+ * @method static Builder truncate()
17+ * @method static Eloquent sole(...$parameters)
18+ */
19+ final class HiddenAnimal extends Eloquent
20+ {
21+ protected $ fillable = [
22+ 'name ' ,
23+ 'country ' ,
24+ 'can_be_eaten ' ,
25+ ];
26+
27+ protected $ hidden = ['country ' ];
28+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace MongoDB \Laravel \Tests \Eloquent ;
6+
7+ use MongoDB \Laravel \Tests \Models \HiddenAnimal ;
8+ use MongoDB \Laravel \Tests \TestCase ;
9+
10+ use function assert ;
11+
12+ final class PropertyTest extends TestCase
13+ {
14+ protected function setUp (): void
15+ {
16+ parent ::setUp ();
17+
18+ HiddenAnimal::truncate ();
19+ }
20+
21+ public function testCanHideCertainProperties (): void
22+ {
23+ HiddenAnimal::create ([
24+ 'name ' => 'Sheep ' ,
25+ 'country ' => 'Ireland ' ,
26+ 'can_be_eaten ' => true ,
27+ ]);
28+
29+ $ hiddenAnimal = HiddenAnimal::sole ();
30+ assert ($ hiddenAnimal instanceof HiddenAnimal);
31+ self ::assertSame ('Ireland ' , $ hiddenAnimal ->country );
32+ self ::assertTrue ($ hiddenAnimal ->can_be_eaten );
33+
34+ self ::assertArrayHasKey ('name ' , $ hiddenAnimal ->toArray ());
35+ self ::assertArrayNotHasKey ('country ' , $ hiddenAnimal ->toArray (), 'the country column should be hidden ' );
36+ self ::assertArrayHasKey ('can_be_eaten ' , $ hiddenAnimal ->toArray ());
37+ }
38+ }
You can’t perform that action at this time.
0 commit comments