kreait / firebase-php

Unofficial Firebase Admin SDK for PHP
https://firebase-php.readthedocs.io/
MIT License
2.27k stars 431 forks source link

FCM CloudMessage - withData() does not work with arrays #768

Closed juhasev closed 1 year ago

juhasev commented 1 year ago

Describe the bug

If you attempt to pass in extra data via array, nothing shows up in the received messages, and when you run $message->jsonSerialize(), the data is also missing.

$message = CloudMessage::withTarget('token', $notificationToken->token)
  ->withData([
                'survey_link' => $this->surveyLink,
            ])

However, if you use, MessageData object, everything works fine.

$message = CloudMessage::withTarget('token', $notificationToken->token)
  ->withData(MessageData::fromArray([
                'survey_link' => $this->surveyLink,
            ]))

Aren't these two supposed to be equivalent?

Installed packages

"require": {
    "php": "^8.1",
    "ext-curl": "*",
    "ext-gd": "*",
    "ext-gmp": "*",
    "ext-json": "*",
    "ext-pcntl": "*",
    "ext-pdo": "*",
    "ext-pdo_mysql": "*",
    "ext-posix": "*",
    "ext-sodium": "*",
    "ext-zip": "*",
    "aws/aws-sdk-php": "^3.48",
    "aws/aws-sdk-php-laravel": "~3.0",
    "bluem/tree": "^2.0",
    "bugsnag/bugsnag-laravel": "^2.0",
    "doctrine/dbal": "3.1.5",
    "elasticsearch/elasticsearch": "~7.0",
    "fakerphp/faker": "^1.14",
    "fruitcake/laravel-cors": "^3.0",
    "hisorange/browser-detect": "^4.5",
    "hyn/multi-tenant": "^5.8.0",
    "intervention/image": "^2.7",
    "juhasev/laravel-ses": "^3.0",
    "juhasev/laravelcdn": "^3.0",
    "kalnoy/nestedset": "^6.0",
    "kamermans/guzzle-oauth2-subscriber": "^1.0",
    "kreait/laravel-firebase": "^5.0",
    "laravel/framework": "^9.0",
    "laravel/horizon": "^5.0",
    "laravel/passport": "^10.0",
    "laravel/ui": "^3.0",
    "lcobucci/jwt": "^4.1",
    "league/csv": "^9.0",
    "league/flysystem-aws-s3-v3": "^3.0",
    "paquettg/php-html-parser": "^2.2",
    "phpoffice/phpspreadsheet": "^1.11",
    "predis/predis": "^1.1",
    "pusher/pusher-php-server": "^6.0",
    "spatie/laravel-permission": "^5.0"
  },

PHP version and extensions

composer               2.5.1    Composer package
composer-plugin-api    2.3.0    The Composer Plugin API
composer-runtime-api   2.2.2    The Composer Runtime API
ext-bcmath             8.1.13   The bcmath PHP extension
ext-bz2                8.1.13   The bz2 PHP extension
ext-calendar           8.1.13   The calendar PHP extension
ext-ctype              8.1.13   The ctype PHP extension
ext-curl               8.1.13   The curl PHP extension
ext-date               8.1.13   The date PHP extension
ext-dba                8.1.13   The dba PHP extension
ext-dom                20031129 The dom PHP extension
ext-exif               8.1.13   The exif PHP extension
ext-ffi                8.1.13   The FFI PHP extension
ext-fileinfo           8.1.13   The fileinfo PHP extension
ext-filter             8.1.13   The filter PHP extension
ext-ftp                8.1.13   The ftp PHP extension
ext-gd                 8.1.13   The gd PHP extension
ext-gettext            8.1.13   The gettext PHP extension
ext-gmp                8.1.13   The gmp PHP extension
ext-hash               8.1.13   The hash PHP extension
ext-iconv              8.1.13   The iconv PHP extension
ext-intl               8.1.13   The intl PHP extension
ext-json               8.1.13   The json PHP extension
ext-ldap               8.1.13   The ldap PHP extension
ext-libxml             8.1.13   The libxml PHP extension
ext-mbstring           8.1.13   The mbstring PHP extension
ext-mysqli             8.1.13   The mysqli PHP extension
ext-mysqlnd            0        The mysqlnd PHP extension (actual version: mysqlnd 8.1.13)
ext-odbc               8.1.13   The odbc PHP extension
ext-openssl            8.1.13   The openssl PHP extension
ext-pcntl              8.1.13   The pcntl PHP extension
ext-pcre               8.1.13   The pcre PHP extension
ext-pdo                8.1.13   The PDO PHP extension
ext-pdo_dblib          8.1.13   The pdo_dblib PHP extension
ext-pdo_mysql          8.1.13   The pdo_mysql PHP extension
ext-pdo_odbc           8.1.13   The PDO_ODBC PHP extension
ext-pdo_pgsql          8.1.13   The pdo_pgsql PHP extension
ext-pdo_sqlite         8.1.13   The pdo_sqlite PHP extension
ext-pgsql              8.1.13   The pgsql PHP extension
ext-phar               8.1.13   The Phar PHP extension
ext-posix              8.1.13   The posix PHP extension
ext-pspell             8.1.13   The pspell PHP extension
ext-readline           8.1.13   The readline PHP extension
ext-reflection         8.1.13   The Reflection PHP extension
ext-session            8.1.13   The session PHP extension
ext-shmop              8.1.13   The shmop PHP extension
ext-simplexml          8.1.13   The SimpleXML PHP extension
ext-soap               8.1.13   The soap PHP extension
ext-sockets            8.1.13   The sockets PHP extension
ext-sodium             8.1.13   The sodium PHP extension
ext-spl                8.1.13   The SPL PHP extension
ext-sqlite3            8.1.13   The sqlite3 PHP extension
ext-sysvmsg            8.1.13   The sysvmsg PHP extension
ext-sysvsem            8.1.13   The sysvsem PHP extension
ext-sysvshm            8.1.13   The sysvshm PHP extension
ext-tidy               8.1.13   The tidy PHP extension
ext-tokenizer          8.1.13   The tokenizer PHP extension
ext-xml                8.1.13   The xml PHP extension
ext-xmlreader          8.1.13   The xmlreader PHP extension
ext-xmlwriter          8.1.13   The xmlwriter PHP extension
ext-xsl                8.1.13   The xsl PHP extension
ext-zend-opcache       8.1.13   The Zend OPcache PHP extension
ext-zip                1.19.5   The zip PHP extension
ext-zlib               8.1.13   The zlib PHP extension
lib-bz2                1.0.8    The bz2 library
lib-curl               7.87.0   The curl library
lib-curl-libssh2       1.10.0   curl libssh2 version
lib-curl-zlib          1.2.11   curl zlib version
lib-date-timelib       2021.17  date timelib version
lib-date-zoneinfo      2022.6   zoneinfo ("Olson") database for date
lib-fileinfo-libmagic  540      fileinfo libmagic version
lib-gd                 2.3.3    The gd library
lib-gmp                6.2.1    The gmp library
lib-icu                71.1     The ICU unicode and globalization support library
lib-icu-cldr           41       ICU CLDR project version
lib-icu-unicode        14.0.0   ICU unicode version
lib-ldap-openldap      2.6.3    OpenLDAP version of ldap
lib-libsodium          1.0.18   The libsodium library
lib-libxml             2.9.13   libxml library version
lib-libxslt            1.1.35   The libxslt library
lib-libxslt-libxml     2.9.13   libxml version libxslt is compiled against
lib-mbstring-libmbfl   1.3.2    mbstring libmbfl version
lib-mbstring-oniguruma 6.9.8    mbstring oniguruma version
lib-openssl            1.1.1.19 OpenSSL 1.1.1s  1 Nov 2022
lib-pcre               10.42    The pcre library
lib-pcre-unicode       14.0.0   PCRE Unicode version support
lib-pdo_pgsql-libpq    15.1     libpq for pdo_pgsql
lib-pdo_sqlite-sqlite  3.40.1   The pdo_sqlite-sqlite library
lib-sqlite3-sqlite     3.40.1   The sqlite3-sqlite library
lib-zip-libzip         1.9.2    The zip-libzip library
lib-zlib               1.2.11   The zlib library
php                    8.1.13   The PHP interpreter
php-64bit              8.1.13   The PHP interpreter, 64bit
php-ipv6               8.1.13   The PHP interpreter, with IPv6 suppor

Steps to reproduce the issue.

Attempt to append data as an array.

Error message/Stack trace

No error.

Additional information

No response

jeromegamez commented 1 year ago

Unfortunately, I can't reproduce the issue. I added a test to confirm that both ways (using an array and an instance of MessageData) work in https://github.com/kreait/firebase-php/blob/b34b21c8b1ee337edb993ab1723d11d9cae27a7b/tests/Unit/Messaging/CloudMessageTest.php#L138-L151, and https://github.com/kreait/firebase-php/actions/runs/4159062416/jobs/7194767977#step:10:360 confirms that it behaves as expected.

If you see an error in the test, please let me know. Otherwise, could you please create a temporary GitHub repo that displays the issue, so that I can inspect the problem further?