Skip to content

Commit 70a09ce

Browse files
authored
Merge pull request #55 from CircleOfNice/bugfixes
fixed id column name issue
2 parents bd9a24e + 37ea0f4 commit 70a09ce

File tree

7 files changed

+91
-9
lines changed

7 files changed

+91
-9
lines changed

Tests/Controller/MockController.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ public function getAction($id) {
4040
if ($id != 1) return new Response('', 404);
4141

4242
return new Response(json_encode([
43-
'id' => 1,
44-
'name' => 'MyName',
45-
'value' => 'MyValue',
43+
'id' => 1,
44+
'extremelyStrange_identifier' => 1,
45+
'name' => 'MyName',
46+
'value' => 'MyValue',
4647
]));
4748
}
4849

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/**
3+
* This file is part of DoctrineRestDriver.
4+
*
5+
* DoctrineRestDriver is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* DoctrineRestDriver is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with DoctrineRestDriver. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
namespace Circle\DoctrineRestDriver\Tests\Entity;
20+
21+
use Doctrine\Common\Collections\ArrayCollection;
22+
use Doctrine\Common\Collections\Collection;
23+
use Doctrine\ORM\Mapping as ORM;
24+
use Circle\DoctrineRestDriver\Annotations as DataSource;
25+
26+
/**
27+
* This is a test entity with a strange named identifier
28+
*
29+
* @author Tobias Hauck <[email protected]>
30+
* @copyright 2015 TeeAge-Beatz UG
31+
*
32+
* @ORM\Entity
33+
* @ORM\Table(name="other_products")
34+
* @SuppressWarnings("PHPMD")
35+
*/
36+
class CustomIdentifierEntity {
37+
/**
38+
* @ORM\Column(type="integer")
39+
* @ORM\Id
40+
* @ORM\GeneratedValue(strategy="AUTO")
41+
* @var int
42+
*/
43+
protected $extremelyStrange_identifier;
44+
45+
/**
46+
* @return int
47+
*/
48+
public function getId() {
49+
return $this->extremelyStrange_identifier;
50+
}
51+
52+
/**
53+
* @param int $id
54+
* @return CustomIdentifierEntity
55+
*/
56+
public function setId($id) {
57+
$this->extremelyStrange_identifier = $id;
58+
return $this;
59+
}
60+
}

Tests/FunctionalTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,19 @@ public function dqlWithObjectParameter() {
291291
* @expectedException \Exception
292292
*/
293293
public function nonImplementedEntity() {
294-
$this->em->find('Circle\DoctrineRestDriver\Entity\NonImplementedEntity', 1);
294+
$this->em->find('Circle\DoctrineRestDriver\Tests\Entity\NonImplementedEntity', 1);
295+
}
296+
297+
/**
298+
* @test
299+
* @group functional
300+
* @covers Circle\DoctrineRestDriver\Driver
301+
* @covers Circle\DoctrineRestDriver\Connection
302+
* @covers Circle\DoctrineRestDriver\Statement
303+
* @covers Circle\DoctrineRestDriver\Statement::<private>
304+
* @covers Circle\DoctrineRestDriver\MetaData
305+
*/
306+
public function customIdentifierEntity() {
307+
$this->em->find('Circle\DoctrineRestDriver\Tests\Entity\CustomIdentifierEntity', 1);
295308
}
296309
}

Tests/RestClientTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ public function send() {
5858
]);
5959

6060
$response = new Response(json_encode([
61-
'id' => 1,
62-
'name' => 'MyName',
63-
'value' => 'MyValue'
61+
'id' => 1,
62+
'extremelyStrange_identifier' => 1,
63+
'name' => 'MyName',
64+
'value' => 'MyValue'
6465
]));
6566

6667
$this->assertEquals($response->getContent(), $this->restClient->send($request)->getContent());

Tests/app/config/routing.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ circle_doctrine_rest_driver_mock_get:
1010
methods: [ GET ]
1111
condition: "request.getScriptName() == '/app_dev.php'"
1212

13+
circle_doctrine_rest_driver_mock_get_custom_identifier:
14+
path: /mockapi/other_products/{id}
15+
defaults: { _controller: Circle\DoctrineRestDriver\Tests\Controller\MockController::getAction }
16+
methods: [ GET ]
17+
condition: "request.getScriptName() == '/app_dev.php'"
18+
1319
circle_doctrine_rest_driver_mock_post:
1420
path: /mockapi/products
1521
defaults: { _controller: Circle\DoctrineRestDriver\Tests\Controller\MockController::postAction }

Types/HttpQuery.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
namespace Circle\DoctrineRestDriver\Types;
2020

2121
use Circle\DoctrineRestDriver\Enums\SqlOperations;
22+
use Circle\DoctrineRestDriver\MetaData;
2223
use Circle\DoctrineRestDriver\Validation\Assertions;
2324

2425
/**
@@ -49,6 +50,6 @@ public static function create(array $tokens) {
4950
return $query . str_replace('"', '', str_replace('OR', '|', str_replace('AND', '&', str_replace($tableAlias . '.', '', $token['base_expr']))));
5051
});
5152

52-
return preg_replace('/id\=\d*&*/', '', $query);
53+
return preg_replace('/' . Identifier::column($tokens, new MetaData()) . '\=\d*&*/', '', $query);
5354
}
5455
}

Types/Identifier.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public static function column(array $tokens, MetaData $metaData) {
8181
return $meta->getTableName() === $table;
8282
});
8383

84-
$idColumns = !empty($meta) ? end($meta)->getIdentifierColumnNames() : [];
84+
$idColumns = !empty($meta) ? end($meta)->getIdentifierColumnNames() : [];
8585

8686
return !empty($idColumns) ? end($idColumns) : 'id';
8787
}

0 commit comments

Comments
 (0)