Skip to content

Commit 5213005

Browse files
committed
Add test cases for calculated property using Attribute
1 parent 1329ccd commit 5213005

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

tests/Console/ModelsCommand/Attributes/Models/Simple.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ function (?string $name): ?string {
2121
);
2222
}
2323

24+
public function uppercaseName(): Attribute
25+
{
26+
return Attribute::get(function (): string {
27+
return strtoupper($this->name);
28+
});
29+
}
30+
2431
/**
2532
* ide-helper does not recognize this method being an Attribute
2633
* because the method has no actual return type;
@@ -40,4 +47,17 @@ function (?string $value): ?string {
4047
}
4148
);
4249
}
50+
51+
/**
52+
* ide-helper does not recognize this method being an Attribute
53+
* because the callable has no specified return type;
54+
*
55+
* @return \Illuminate\Database\Eloquent\Casts\Attribute
56+
*/
57+
public function alsoNotAnAttribute(): Attribute
58+
{
59+
return Attribute::get(function () {
60+
return strtoupper($this->name);
61+
});
62+
}
4363
}

tests/Console/ModelsCommand/Attributes/__snapshots__/Test__test__1.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*
1313
* @property integer $id
1414
* @property string|null $name
15+
* @property-read string $uppercase_name
1516
* @method static \Illuminate\Database\Eloquent\Builder|Simple newModelQuery()
1617
* @method static \Illuminate\Database\Eloquent\Builder|Simple newQuery()
1718
* @method static \Illuminate\Database\Eloquent\Builder|Simple query()
@@ -32,6 +33,13 @@ function (?string $name): ?string {
3233
);
3334
}
3435

36+
public function uppercaseName(): Attribute
37+
{
38+
return Attribute::get(function (): string {
39+
return strtoupper($this->name);
40+
});
41+
}
42+
3543
/**
3644
* ide-helper does not recognize this method being an Attribute
3745
* because the method has no actual return type;
@@ -51,4 +59,17 @@ function (?string $value): ?string {
5159
}
5260
);
5361
}
62+
63+
/**
64+
* ide-helper does not recognize this method being an Attribute
65+
* because the callable has no specified return type;
66+
*
67+
* @return \Illuminate\Database\Eloquent\Casts\Attribute
68+
*/
69+
public function alsoNotAnAttribute(): Attribute
70+
{
71+
return Attribute::get(function () {
72+
return strtoupper($this->name);
73+
});
74+
}
5475
}

0 commit comments

Comments
 (0)