Skip to content
This repository was archived by the owner on Jul 17, 2020. It is now read-only.

Commit 55a2ba8

Browse files
authored
Merge pull request #58 from niels-nijens/fix-file-upload
Fix UploadTrait::getFileUpload
2 parents a9e57e2 + 9cb4ace commit 55a2ba8

3 files changed

Lines changed: 47 additions & 1 deletion

File tree

Model/UploadTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ trait UploadTrait
2727
*/
2828
public function getFileUpload()
2929
{
30-
$propertyName = $this->getFileUploadPropertyName();
30+
$propertyName = $this->getFileUploadPropertyName(__FUNCTION__);
3131

3232
if (isset($this->fileUploads[$propertyName])) {
3333
return $this->fileUploads[$propertyName];

Tests/Model/UploadTraitTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,40 @@ public function testSetFileUploadFromProxy()
6161
$uploadEntityProxyMock
6262
);
6363
}
64+
65+
/**
66+
* Tests if the UploadEntityMock::getImageUpload (alias of UploadTrait::getFileUpload)
67+
* returns the expected file uploads property.
68+
*/
69+
public function testGetFileUpload()
70+
{
71+
$uploadedFileMock = $this->getMockBuilder(UploadedFile::class)
72+
->disableOriginalConstructor()
73+
->getMock();
74+
75+
$entityMock = new UploadEntityMock();
76+
$entityMock->setImageUpload($uploadedFileMock);
77+
78+
$this->assertSame($uploadedFileMock, $entityMock->getImageUpload($uploadedFileMock));
79+
}
80+
81+
/**
82+
* Tests if the UploadEntityProxyMock::getImageUpload (alias of UploadTrait::getFileUpload)
83+
* sets the expected file uploads property.
84+
*
85+
* This tests the scenario of a Doctrine entity being a parent class of
86+
* a proxy class with all the method overloaded as this changes the
87+
* PHP stack to determine the caller method.
88+
*/
89+
public function testGetFileUploadFromProxy()
90+
{
91+
$uploadedFileMock = $this->getMockBuilder(UploadedFile::class)
92+
->disableOriginalConstructor()
93+
->getMock();
94+
95+
$uploadEntityProxyMock = new UploadEntityProxyMock();
96+
$uploadEntityProxyMock->setImageUpload($uploadedFileMock);
97+
98+
$this->assertSame($uploadedFileMock, $uploadEntityProxyMock->getImageUpload($uploadedFileMock));
99+
}
64100
}

Tests/UploadEntityProxyMock.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@
1111
*/
1212
class UploadEntityProxyMock extends UploadEntityMock
1313
{
14+
/**
15+
* Overloaded trait method alias.
16+
*
17+
* @return UploadedFile
18+
*/
19+
public function getImageUpload()
20+
{
21+
return parent::getImageUpload();
22+
}
23+
1424
/**
1525
* Overloaded trait method alias.
1626
*

0 commit comments

Comments
 (0)