laravel-ardent / ardent

Self-validating, secure and smart models for Laravel's Eloquent ORM
BSD 3-Clause "New" or "Revised" License
1.39k stars 211 forks source link

Should not depend on Input::hasSessionStore() #155

Open pesterhazy opened 10 years ago

pesterhazy commented 10 years ago

I use Entrust, which depends on Ardent. I recently upgraded to Laravel 4.1. Now my tests fail with the following backtrace:

PHP Fatal error:  Call to undefined method Illuminate\Http\Input::hasSessionStore() in /vagrant/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php on line 205
PHP Stack trace:
PHP   1. {main}() /vagrant/vendor/phpunit/phpunit/composer/bin/phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() /vagrant/vendor/phpunit/phpunit/composer/bin/phpunit:63
PHP   3. PHPUnit_TextUI_Command->run() /vagrant/vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php:129
PHP   4. PHPUnit_TextUI_TestRunner->doRun() /vagrant/vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php:176
PHP   5. PHPUnit_Framework_TestSuite->run() /vagrant/vendor/phpunit/phpunit/PHPUnit/TextUI/TestRunner.php:349
PHP   6. PHPUnit_Framework_TestSuite->run() /vagrant/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php:705
PHP   7. PHPUnit_Framework_TestSuite->runTest() /vagrant/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php:745
PHP   8. PHPUnit_Framework_TestCase->run() /vagrant/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php:775
PHP   9. PHPUnit_Framework_TestResult->run() /vagrant/vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php:783
PHP  10. PHPUnit_Framework_TestCase->runBare() /vagrant/vendor/phpunit/phpunit/PHPUnit/Framework/TestResult.php:648
PHP  11. PHPUnit_Framework_TestCase->runTest() /vagrant/vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php:838
PHP  12. ReflectionMethod->invokeArgs() /vagrant/vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php:983
PHP  13. ApiAgencyTest->testPermissions() /vagrant/vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php:983
PHP  14. PermissionTableSeeder->run() /vagrant/app/tests/controllers/api/ApiAgencyTest.php:145
PHP  15. LaravelBook\Ardent\Ardent->save() /vagrant/app/database/seeds/real_seeder/PermissionTableSeeder.php:120
PHP  16. LaravelBook\Ardent\Ardent->internalSave() /vagrant/vendor/laravelbook/ardent/src/LaravelBook/Ardent/Ardent.php:605
PHP  17. LaravelBook\Ardent\Ardent->validate() /vagrant/vendor/laravelbook/ardent/src/LaravelBook/Ardent/Ardent.php:578
PHP  18. Illuminate\Support\Facades\Input::hasSessionStore() /vagrant/vendor/laravelbook/ardent/src/LaravelBook/Ardent/Ardent.php:535
PHP  19. Illuminate\Support\Facades\Facade::__callStatic() /vagrant/vendor/laravelbook/ardent/src/LaravelBook/Ardent/Ardent.php:535

The reason seems to be that the method call Input::hasSessionStore() has been removed as of Laravel 4.1.

In my test no session store is available, I think.

pesterhazy commented 10 years ago

This patch seems to fix the error message. I'm not entirely sure that calling Request::hasSession() is the right thing to do.

From 72c30075cc2753d774d57f1afe1008f258cf313e Mon Sep 17 00:00:00 2001
From: Paulus Esterhazy <pesterhazy@gmail.com>
Date: Thu, 16 Jan 2014 12:36:35 +0100
Subject: [PATCH 1/1] remove reference to Input::hasSessionStorage(), which
 doesn't exist in Laravel 4.1 anymore

---
 src/LaravelBook/Ardent/Ardent.php | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/LaravelBook/Ardent/Ardent.php b/src/LaravelBook/Ardent/Ardent.php
index 271f543..6bd60de 100644
--- a/src/LaravelBook/Ardent/Ardent.php
+++ b/src/LaravelBook/Ardent/Ardent.php
@@ -16,6 +16,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
 use Illuminate\Events\Dispatcher;
 use Illuminate\Support\MessageBag;
 use Illuminate\Support\Facades\Input;
+use Illuminate\Support\Facades\Request;
 use Illuminate\Support\Facades\Hash;
 use Illuminate\Support\Facades\Validator;
 use Illuminate\Database\Eloquent\Model;
@@ -531,7 +532,7 @@ abstract class Ardent extends Model {
                $this->validationErrors = $validator->messages();

                // stash the input to the current session
-               if (!self::$externalValidator && Input::hasSessionStore()) {
+               if (!self::$externalValidator && Request::hasSession()) {
                    Input::flash();
                }
            }
-- 
1.8.3.2
LimeBlast commented 10 years ago

I'm getting the same problem when I run my tests.

ghost commented 10 years ago

Same problem occurring here on a fresh install of Laravel 4.1 and just following the setup guide. The exception is reported as: Symfony \ Component \ Debug \ Exception \ FatalErrorException

Call to undefined method Illuminate\Http\Request::hasSessionStore()

globsecure commented 10 years ago

+1

IgnitedCoder commented 10 years ago

Same error here... huge site so need a fix please. Also it produces the error when seeding the Users table which worked great before.

LimeBlast commented 10 years ago

If you update your composer.json to include the repositories chunk found here: https://github.com/laravelbook/ardent/pull/133#issuecomment-30669346 - it'll provide a temporary fix (at least it did for me)

wemersonjanuario commented 10 years ago

thanks for you temporary fix

IgnitedCoder commented 10 years ago

Tried the temp fix in my composer.json file and still no luck... none of the test users can register now at all. Call to undefined method Illuminate\Http\Request::hasSessionStore()

Please provide a fix.

LimeBlast commented 10 years ago

I'm in no way qualified to answer any of these questions, and so what I'm about to say could be totally backwards, but after you added in the repositories bit, did you do a composer update?

IgnitedCoder commented 10 years ago

Absolutely... composer update :) and no what you said is not totally backwards, its good to check... Its easy to forget to run composer commands.

Thanks

IgnitedCoder commented 10 years ago

Ok this fixed it... I went back a version on Laravel... "laravel/framework": "4.1.16",

run composer update. I guess this will have to do until this issues is resolved.

LimeBlast commented 10 years ago

I have no idea how to actually go about doing this, but the only other thing I can think of is to drop back to an version of Laravel that still has the Input::hasSessionStore() method

I'd suggest starting by looking here: https://packagist.org/packages/laravel/framework

then modifying the "laravel/framework": "4.1.*", line in composer.json to "laravel/framework": "4.1.18", then running composer update. If you still get the issue, swap it out for 4.1.17 and try again.

Keep doing this until you find one that works (then report back here and let us all know which one works.

LimeBlast commented 10 years ago

Ha, you beat me to it, good job :)

davidthingsaker commented 10 years ago

I had the same error appearing when using a simple validation on an email field. I dropped down from 4.1.18 to 4.1.16 and works fine.

IgnitedCoder commented 10 years ago

@LimeBlast - No worries, your feedback is most appreciated.

pesterhazy commented 10 years ago

Here's the Laravel commit that removed Request::hasSessionStore(): https://github.com/laravel/framework/commit/328e6cf72442aff228f1c60800ea4f1f9c1bf2cf

dalabarge commented 10 years ago

@LimeBlast thanks for digging. For those using Entrust, you'll need to manually set your Ardent tag to 2.4.1 as Entrust has switched to requiring 2.4.x which if you use Ardent's repo will be 2.4.0. You can use this composer.json block to fix that. It essentially forces a package version of 2.4.1 that points to my fork's (or yours if you change it) to the HEAD of master. It's a slight improvement over #133 block. It's been tested to be compatible with 4.1.18 so you don't have to be dropped back to 4.1.16.

"require": [
        "laravelbook/ardent": "2.4.1"
],
"repositories": [
        {
                "type": "package",
                "package": {
                        "name": "laravelbook/ardent",
                        "version": "2.4.2",
                        "source": {
                                "type": "git",
                                "url": "https://github.com/bexarcreativeinc/ardent.git",
                                "reference": "master"
                        },
                        "require": {
                                "php": ">=5.3.0",
                                "illuminate/support": "4.x",
                                "illuminate/database": "4.x",
                                "illuminate/validation": "4.x"
                        },
                        "autoload": {
                                "psr-0": {
                                        "LaravelBook\\Ardent": "src/"
                                }
                        }
                }
        }
]
58bits commented 10 years ago

thanks @bexarcreative-daniel. Is there likely to be an official ardent 2.4.1 release soon?

tbergeron commented 10 years ago

I had this error has well, using an early version of Laravel fixed it. It'd be interesting to have a release to fix this issue though :+1:

dalabarge commented 10 years ago

@58bits I've released a similar MIT licensed package that uses traits and is unit tested and is compatible with Laravel 4.2. You might want to consider it if you need more frequent tag releases. http://github.com/esensi/model