feat: add support for deprecated fields to PHP compiler (#8223)
* feat: add support for deprecated fields to PHP compiler
* PR feedback 1
diff --git a/php/tests/GeneratedClassTest.php b/php/tests/GeneratedClassTest.php
index f3f74d1..c0de0ba 100644
--- a/php/tests/GeneratedClassTest.php
+++ b/php/tests/GeneratedClassTest.php
@@ -72,6 +72,33 @@
}
#########################################################
+ # Test deprecated int32 field.
+ #########################################################
+
+ public function testDeprecatedInt32Field()
+ {
+ $m = new TestMessage();
+
+ // temporarily change error handler to capture the deprecated errors
+ $deprecationCount = 0;
+ set_error_handler(function ($errno, $errstr) use (&$deprecationCount) {
+ if ($errstr === 'deprecated_optional_int32 is deprecated.') {
+ $deprecationCount++;
+ }
+ }, E_USER_DEPRECATED);
+
+ // default test set
+ $m->setDeprecatedOptionalInt32(MAX_INT32);
+ $this->assertSame(MAX_INT32, $m->getDeprecatedOptionalInt32());
+ $m->setDeprecatedOptionalInt32(MIN_INT32);
+ $this->assertSame(MIN_INT32, $m->getDeprecatedOptionalInt32());
+
+ restore_error_handler();
+
+ $this->assertSame(4, $deprecationCount);
+ }
+
+ #########################################################
# Test optional int32 field.
#########################################################