Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phalcon\Flash\Session getMessages bug #11283

Closed
chiWahWong opened this issue Jan 7, 2016 · 17 comments
Closed

Phalcon\Flash\Session getMessages bug #11283

chiWahWong opened this issue Jan 7, 2016 · 17 comments

Comments

@chiWahWong
Copy link

Bug: if with a TRUE for the 2nd parameter or without it, ALL types are removed.
Special thank to Lajos Bencz, he found out the line https://github.com/phalcon/cphalcon/blob/phalcon-v2.0.9/phalcon/flash/session.zep#L70

@sergeyklay
Copy link
Contributor

This is a bug? Obviously if you have received messages from the session, you do not want to receive their again. In any case you can use getMessages(null, false)

@chiWahWong
Copy link
Author

This is not a bug? Obviously if I'm trying to remove ONE particular type, not ALL other types should be removed.
And have you use getMessages in the previous version? Do you know how it used to and was intended to work? Or have you read the doc? Here is one related resource that you may like to read: #1575

@sergeyklay
Copy link
Contributor

Can you please try 2.0.x branch?

@chiWahWong
Copy link
Author

The bug is at least from 2.0.9; 2.0.9 is the version that I am using and when I incidentally realize the bug. The version information is on my first comment too. When I was using 1.3.4 it works fine.

@sergeyklay
Copy link
Contributor

We don't add changes directly to stable branches. Currently development branch is 2.0.x (in the future 2.0.10). This issue is solved in 2.0.x branch.

@chiWahWong
Copy link
Author

I just installed 2.0.x, the result is the same; the bug is still there. I would like to confirm the version; it is the "2001040" when executing \Phalcon\Version::getId(), correct?

@sergeyklay
Copy link
Contributor

@sergeyklay
Copy link
Contributor

$ php --ri phalcon

phalcon


Web framework delivered as a C-extension for PHP
phalcon => enabled
Author => Phalcon Team and contributors
Version => 2.0.10
Build Date => Dec 19 2015 14:06:30
Powered by Zephir => Version 0.9.1a-dev

Directive => Local Value => Master Value
phalcon.db.escape_identifiers => On => On
phalcon.db.force_casting => Off => Off
phalcon.orm.events => On => On
phalcon.orm.virtual_foreign_keys => On => On
phalcon.orm.column_renaming => On => On
phalcon.orm.not_null_validations => On => On
phalcon.orm.exception_on_failed_save => Off => Off
phalcon.orm.enable_literals => On => On
phalcon.orm.late_state_binding => Off => Off
phalcon.orm.enable_implicit_joins => On => On
phalcon.orm.cast_on_hydrate => Off => Off
phalcon.orm.ignore_unknown_columns => Off => Off
$ php -r 'echo \Phalcon\Version::getId(), PHP_EOL;'
2001040
$ git status
On branch 2.0.x
Your branch is up-to-date with 'phalcon/2.0.x'.

nothing to commit, working directory clean
$ git show
commit fe827a440bb5b4c4f4fe749dae5391dfbaefe1a5
Merge: 42ea223 b18140f
Author: Andy Gutierrez <gutierrezandresfelipe@gmail.com>
Date:   Thu Jan 7 11:13:44 2016 -0500

    Merge pull request #11278 from ifsnow/2.0.x

    Fixed for building on windows.
$ php codecept.phar run tests/unit/Phalcon/Flash/Session/FlashSessionDefaultTest.php 
Codeception PHP Testing Framework v2.0.7
Powered by PHPUnit 4.3.1 by Sebastian Bergmann.

Unit Tests (4) --------------------------------------------------------------------------------------------------------------------------------------------------------
Trying to test get messages type remove messages (Phalcon\Tests\unit\Phalcon\Flash\Session\FlashSessionDefaultTest::testGetMessagesTypeRemoveMessages)            Ok
Trying to test clear (Phalcon\Tests\unit\Phalcon\Flash\Session\FlashSessionDefaultTest::testClear)                                                                Ok
Trying to test string with data set "error" (Phalcon\Tests\unit\Phalcon\Flash\Session\FlashSessionDefaultTest::testString)                                        Ok
Trying to test string with data set "success" (Phalcon\Tests\unit\Phalcon\Flash\Session\FlashSessionDefaultTest::testString)                                      Ok
Trying to test string with data set "notice" (Phalcon\Tests\unit\Phalcon\Flash\Session\FlashSessionDefaultTest::testString)                                       Ok
Trying to test string data provider (Phalcon\Tests\unit\Phalcon\Flash\Session\FlashSessionDefaultTest::testStringDataProvider)                                    Ok
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------


Time: 78 ms, Memory: 9.25Mb

OK (6 tests, 7 assertions)

@chiWahWong
Copy link
Author

I did the practical test:

$this->flash_session->success('test success');
$this->flash_session->error('test error');
$this->flash_session->notice('test notice');
echo "<pre>"; var_dump($this->flash_session->getMessages(NULL, FALSE)); echo "</pre>"; // all three types are there
echo "<pre>"; var_dump($this->flash_session->getMessages('error', TRUE)); echo "</pre>"; // output only the error type
echo "<pre>"; var_dump($this->flash_session->getMessages(NULL, FALSE)); echo "</pre>"; // nothing left

@sergeyklay
Copy link
Contributor

<?php

use Phalcon\Di;
use Phalcon\Flash\Session;
use Phalcon\Session\Adapter\Files;

$flash = new Session;
$di    = new Di;

$di->setShared('session', function () {
    $session = new Files;
    $session->start();
    return $session;
});

$flash->setDI($di);

$flash->success('sample success');
$flash->error('sample error');
$flash->notice('sample notice');

$expectedMessages = [
    'success' => ['sample success'],
    'error'   => ['sample error'],
    'notice'  => ['sample notice'],
];

assert($flash->getMessages(null, false) === $expectedMessages);
assert($flash->getMessages('success') === ['sample success']);
assert($flash->getMessages('error') === ['sample error']);
assert(['notice'  => ['sample notice']] === $flash->getMessages());
assert(null === $flash->getMessages());

@chiWahWong
Copy link
Author

assert($flash->getMessages(null, false) === $expectedMessages); // I get TRUE
assert($flash->getMessages('success') === ['sample success']); // I get TRUE
assert($flash->getMessages('error') === ['sample error']); // I get NULL
assert(['notice'  => ['sample notice']] === $flash->getMessages()); // I get NULL

@sergeyklay
Copy link
Contributor

Can you please provide OS name/version and $ php --ri phalcon output?

@chiWahWong
Copy link
Author

phalcon


Web framework delivered as a C-extension for PHP
phalcon => enabled
Author => Phalcon Team and contributors
Version => 2.0.10
Build Date => Jan  7 2016 19:06:38
Powered by Zephir => Version 0.9.1a-dev

Directive => Local Value => Master Value
phalcon.db.escape_identifiers => On => On
phalcon.db.force_casting => Off => Off
phalcon.orm.events => On => On
phalcon.orm.virtual_foreign_keys => On => On
phalcon.orm.column_renaming => On => On
phalcon.orm.not_null_validations => On => On
phalcon.orm.exception_on_failed_save => Off => Off
phalcon.orm.enable_literals => On => On
phalcon.orm.late_state_binding => Off => Off
phalcon.orm.enable_implicit_joins => On => On
phalcon.orm.cast_on_hydrate => Off => Off
phalcon.orm.ignore_unknown_columns => Off => Off

@sergeyklay
Copy link
Contributor

Cannot reproduce this.
Right now I have compilled latest version:

# php --ri phalcon

phalcon


Web framework delivered as a C-extension for PHP
phalcon => enabled
Author => Phalcon Team and contributors
Version => 2.0.10
Build Date => Jan  8 2016 03:02:54
Powered by Zephir => Version 0.9.1a-dev

Directive => Local Value => Master Value
phalcon.db.escape_identifiers => On => On
phalcon.db.force_casting => Off => Off
phalcon.orm.events => On => On
phalcon.orm.virtual_foreign_keys => On => On
phalcon.orm.column_renaming => On => On
phalcon.orm.not_null_validations => On => On
phalcon.orm.exception_on_failed_save => Off => Off
phalcon.orm.enable_literals => On => On
phalcon.orm.late_state_binding => Off => Off
phalcon.orm.enable_implicit_joins => On => On
phalcon.orm.cast_on_hydrate => Off => Off
phalcon.orm.ignore_unknown_columns => Off => Off
$ php session_test.php  # all ok, all assertions described above passes  

@chiWahWong
Copy link
Author

First of all I am sorry for my attitude earlier and I am sorry for bothering you so much.
Could it because I am using the safe build? Without using the safe build there are other problems.

@sergeyklay
Copy link
Contributor

  • Did you used the test provided by me above exactly and unchanged?
  • Did you run the test in console mode?
  • Did you restart PHP-FPM after compiling new Phalcon (if you are used PHP-FPM)?
  • Provide please your version of PHP (use php-config output) and OS.
  • Try to use not safe build

@chiWahWong
Copy link
Author

"Did you used the test provided by me above exactly and unchanged?"
Yes, from the line "$flash->success('sample success');" and below are the same.

"Did you run the test in console mode?"
No, I run the test normally, I see the result from my browser.

"Did you restart PHP-FPM after compiling new Phalcon (if you are used PHP-FPM)?"
I restart the entire server.

my version of PHP is 5.4.16, my OS is CentOS 7

"Try to use not safe build"
Unfortunately I basically have to. Because my application couldn't even function without the safe mode, there will be errors like #2082

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants