Skip to content

Commit 75040be

Browse files
alexander-schranzsaimaz
authored andcommitted
Fix php 7.2 compatibility for Elasticsearch 2 (#860)
* fix php 7.2 compatibility for ongr 1.x * ugprade phpunit for compatibility of mocks * fixed phpunit deprecations * fix exception test * Revert "fixed phpunit deprecations" This reverts commit c96ba36. * fix phpunit compatibility for php 5.5
1 parent 4212408 commit 75040be

File tree

10 files changed

+43
-16
lines changed

10 files changed

+43
-16
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ php:
44
- 5.5
55
- 5.6
66
- 7.0
7+
- 7.1
8+
- 7.2
79
- hhvm
810
env:
911
global:

Annotation/Object.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,7 @@
1111

1212
namespace ONGR\ElasticsearchBundle\Annotation;
1313

14-
/**
15-
* Annotation to mark a class as an object during the parsing process.
16-
*
17-
* @Annotation
18-
* @Target("CLASS")
19-
*/
20-
final class Object
21-
{
14+
if (version_compare(PHP_VERSION, '7.2.0') < 0) {
15+
class_alias('ONGR\ElasticsearchBundle\Annotation\ObjectType', 'ONGR\ElasticsearchBundle\Annotation\Object', false);
16+
class_exists('ONGR\ElasticsearchBundle\Annotation\ObjectType');
2217
}

Annotation/ObjectType.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the ONGR package.
5+
*
6+
* (c) NFQ Technologies UAB <info@nfq.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace ONGR\ElasticsearchBundle\Annotation;
13+
14+
/**
15+
* Annotation to mark a class as an object during the parsing process.
16+
*
17+
* @Annotation
18+
* @Target("CLASS")
19+
*/
20+
final class ObjectType
21+
{
22+
}

Mapping/DocumentParser.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class DocumentParser
2929
const PROPERTY_ANNOTATION = 'ONGR\ElasticsearchBundle\Annotation\Property';
3030
const EMBEDDED_ANNOTATION = 'ONGR\ElasticsearchBundle\Annotation\Embedded';
3131
const DOCUMENT_ANNOTATION = 'ONGR\ElasticsearchBundle\Annotation\Document';
32-
const OBJECT_ANNOTATION = 'ONGR\ElasticsearchBundle\Annotation\Object';
32+
const OBJECT_ANNOTATION = 'ONGR\ElasticsearchBundle\Annotation\ObjectType';
3333
const NESTED_ANNOTATION = 'ONGR\ElasticsearchBundle\Annotation\Nested';
3434

3535
// Meta fields
@@ -354,7 +354,7 @@ private function registerAnnotations()
354354
'Document',
355355
'Property',
356356
'Embedded',
357-
'Object',
357+
'ObjectType',
358358
'Nested',
359359
'Id',
360360
'ParentDocument',
@@ -366,6 +366,10 @@ private function registerAnnotations()
366366
foreach ($annotations as $annotation) {
367367
AnnotationRegistry::registerFile(__DIR__ . "/../Annotation/{$annotation}.php");
368368
}
369+
370+
if (version_compare(PHP_VERSION, '7.2.0') < 0) {
371+
AnnotationRegistry::registerFile(__DIR__ . "/../Annotation/Object.php");
372+
}
369373
}
370374

371375
/**
@@ -491,7 +495,7 @@ private function getObjectMapping($className)
491495
default:
492496
throw new \LogicException(
493497
sprintf(
494-
'%s should have @Object or @Nested annotation to be used as embeddable object.',
498+
'%s should have @ObjectType or @Nested annotation to be used as embeddable object.',
495499
$className
496500
)
497501
);

Resources/doc/mapping.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ namespace AppBundle\Document;
157157
use ONGR\ElasticsearchBundle\Annotation as ES;
158158

159159
/**
160-
* @ES\Object
160+
* @ES\ObjectType
161161
*/
162162
class ContentMetaObject
163163
{

Tests/Functional/Mapping/DocumentParserTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class DocumentParserTest extends WebTestCase
2222
* Test if exception is thrown when Document is used as embeddable.
2323
*
2424
* @expectedException \LogicException
25-
* @expectedExceptionMessage should have @Object or @Nested annotation
25+
* @expectedExceptionMessage should have @ObjectType or @Nested annotation
2626
*/
2727
public function testGetDocumentTypeException()
2828
{

Tests/Unit/DependencyInjection/Compiler/MappingPassTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ function ($parameter) use ($metadataCollectorMock) {
140140
*/
141141
public function testProcessWithSeveralManagers(array $connections, array $managers)
142142
{
143+
if (version_compare(PHP_VERSION, '5.6.0') > 0) {
144+
$this->markTestSkipped('Skipped because of a bug in phpunit 4 mock which is needed for php 5.5 tests');
145+
}
146+
143147
$compilerPass = new MappingPass();
144148
$compilerPass->process($this->getContainerMock($connections, $managers));
145149
}

Tests/app/fixture/Acme/BarBundle/Document/CategoryObject.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/**
1717
* Category document for testing.
1818
*
19-
* @ES\Object
19+
* @ES\ObjectType
2020
*/
2121
class CategoryObject
2222
{

Tests/app/fixture/Acme/BarBundle/Document/Person/Address.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/**
1717
* Category document for testing.
1818
*
19-
* @ES\Object
19+
* @ES\ObjectType
2020
*/
2121
class Address
2222
{

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
},
2323
"require-dev": {
2424
"mikey179/vfsStream": "~1.4",
25-
"phpunit/phpunit": "~4.4",
25+
"phpunit/phpunit": "~4.8 || ~5.6",
2626
"squizlabs/php_codesniffer": "~2.0",
2727
"satooshi/php-coveralls": "~1.0"
2828
},

0 commit comments

Comments
 (0)