Error assert(): assert(sizeof($failures) == 1) failed stops Codeception Test - codeception

At some point, while adding assertions for my test, I got the following error message during a test run which stops the execution of the test
Testing started at 14:28 ...
C:\xampp\php\php.exe C:/Users/georg/AppData/Local/Temp/ide-codeception.php run --report -o "reporters: report: PhpStorm_Codeception_ReportPrinter" --no-interaction -c C:/Users/georg/Documents/CMS_Automation_Tests/codeception.yml "tests\regression\features\ArticleTests.feature:Create a new article and fill out all available fields"
Codeception PHP Testing Framework v4.1.7
Powered by PHPUnit 9.3.8 by Sebastian Bergmann and contributors.
Running with seed:
In ErrorHandler.php line 83:
assert(): assert(sizeof($failures) == 1) failed
run [-o|--override OVERRIDE] [-e|--ext EXT] [--report] [--html [HTML]] [--xml [XML]] [--phpunit-xml [PHPUNIT-XML]] [--tap [TAP]] [--json [JSON]] [--colors] [--no-colors] [--silent] [--steps] [-d|--debug] [--bootstrap [BOOTSTRAP]] [--no-redirect] [--coverage [COVERAGE]] [--coverage-html [COVERAGE-HTML]] [--coverage-xml [COVERAGE-XML]] [--coverage-text [COVERAGE-TEXT]] [--coverage-crap4j [COVERAGE-CRAP4J]] [--coverage-phpunit [COVERAGE-PHPUNIT]] [--no-exit] [-g|--group GROUP] [-s|--skip SKIP] [-x|--skip-group SKIP-GROUP] [--env ENV] [-f|--fail-fast] [--no-rebuild] [--seed SEED] [--no-artifacts] [--] [<suite> [<test>]]
I didn't find any information about this error. It doesn't seem to be related to any specific error in my code.
My composer.json is below:
{
"name": "cms/automation",
"type": "project",
"require": {
"php": "^7.2",
"ext-json": "*",
"fzaninotto/faker": "^1.7",
"php-webdriver/webdriver": "^1.8#dev",
"ext-curl": "*",
"ext-zip": "*",
"ext-mb$ vendor/bin/behat -V\nstring": "*",
"facebook/webdriver": "1.7"
},
"require-dev": {
"phpunit/phpunit": "^6.5",
"mockery/mockery": "~0.9",
"codeception/codeception": "^4.1",
"codeception/base": "^2.4",
"symfony/var-dumper": "^4.1",
"behat/behat": "^3.6"
},
"autoload": {
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"classmap": [
"tests/"
]
},
"minimum-stability": "dev",
"prefer-stable": true
}

Related

syntax error, unexpected '#', expecting variable (T_VARIABLE) or '{' or '$'

I'am using php 7.4.27, laravel framework 8.83.7 and installed Laravel Jetstream.
Login & Register can show. After registered, Then an error notification appears in Laravel:
syntax error, unexpected '#', expecting variable (T_VARIABLE) or '{' or '$'
and in code line 12 :
<?php $component = $__env->getContainer()->make(Illuminate\View\AnonymousComponent::class, ['view' => 'jetstream::components.dropdown-link','data' => ['href' => $href,'#click.prevent' => $#clickPrevent]]); ?>
I won't update to php 8. What should i do?
=====edited=====
composer.json file :
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"php": "^7.3|^8.0",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0.1",
"laravel/framework": "^8.75",
"laravel/jetstream": "^2.7",
"laravel/sanctum": "^2.11",
"laravel/tinker": "^2.5",
"livewire/livewire": "^2.5"
},
"require-dev": {
"facade/ignition": "^2.5",
"fakerphp/faker": "^1.9.1",
"laravel/sail": "^1.0.1",
"mockery/mockery": "^1.4.4",
"nunomaduro/collision": "^5.10",
"phpunit/phpunit": "^9.5.10"
},
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"#php artisan package:discover --ansi"
],
"post-update-cmd": [
"#php artisan vendor:publish --tag=laravel-assets --ansi --force"
],
"post-root-package-install": [
"#php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"#php artisan key:generate --ansi"
]
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true
}
Explanation:
The issue comes from the fact that the compiled view version under storage/framework/views is failing to evaluate $#clickPrevent.
<?php $component = $__env->getContainer()->make(Illuminate\View\AnonymousComponent::class, ['view' => 'jetstream::components.dropdown-link','data' => ['href' => $href,'#click.prevent' => $#clickPrevent]]); ?>
This has nothing to do with your current PHP version.
Solution:
I managed to locally reproduce the issue. Here is how I solved it.
Steps:
Publish the Jetstream Livewire components.
Command:
php artisan vendor:publish --tag=jetstream-views
Open the file resources/views/vendor/jetstream/components/switchable-team.blade.php
In the file contents,
Instead of:
<x-dynamic-component :component="$component" href="#" #click.prevent="$root.submit();"> ❌
Use this:
<x-dynamic-component :component="$component" href="#"> ✅
Disclaimer:
Note that this is a temporary solution. Everything works fine for me. As lamented by #IMSoP in a comment, I'm afraid it may affect some unknown functionality. I've opened an issue against the library here:
switchable-team.blade.php compiled Jetstream component throwing an error: syntax error, unexpected token "#", expecting variable or "{" or "$"
Update 10th/April/2022:
Another "more stable" solution stated by #fabpl on the opened Github issue:
I think it's the same bug like [2.x] Fix parse error caused by alpine
shorthand on dynamic-component
#1032
Try to replace #click with x-on:click
https://github.com/laravel/jetstream/issues/1036#issuecomment-1094253898
Addendum:
The issue seems to have been introduced in laravel/jetstream v2.7.2. More specifically Use Alpine's #click.prevent for switching teams.
The good news is that this has been resolved beginning from laravel/jetstream v2.7.3 onwards. More specifically [2.x] Fix parse error caused by alpine shorthand on dynamic-component.
I just tagged v2.7.3 which should fix this. Thanks all 👍
https://github.com/laravel/jetstream/issues/1036#issuecomment-1094332998
Hence, you may simply just upgrade your Jetstream version to v2.7.3 to get the fix. I.e:
Command:
composer update laravel/jetstream:2.7.3
Sample Output:
PS C:\Users\Ivan\Documents\SteveContents\GITHUB\Laravel-8.83.7\laravel-8.83.7> composer update laravel/jetstream:2.7.3
Loading composer repositories with package information
Info from https://repo.packagist.org: #StandWithUkraine
Updating dependencies
Lock file operations: 0 installs, 1 update, 0 removals
- Upgrading laravel/jetstream (v2.7.2 => v2.7.3)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 0 installs, 1 update, 0 removals
- Downloading laravel/jetstream (v2.7.3)
- Downloading laravel/jetstream (v2.7.3)
- Downloading laravel/jetstream (v2.7.3)
- Downloading laravel/jetstream (v2.7.3)
- Upgrading laravel/jetstream (v2.7.2 => v2.7.3): Extracting archive
...

Updating from Laravel 5.8 to 6.0 fails due to dependencies

I'm trying to update from 5.8 to any version 6 Laravel. I've updated the PHP code, but the composer update is problematic for me. I've tried composer update, composer update --with-dependencies, composer install.
Composer isn't something I work with often. Any help is very appreciate! How do I decipher the composer error message to an actionable task? Is there a command that will install the dependencies for Laravel 6?
The error message after composer update:
- Conclusion: don't install laravel/framework v6.0.0
- arcanedev/support 4.5.0 requires illuminate/support ~5.8.0 -> satisfiable by laravel/framework[v5.8.38], illuminate/support[5.8.x-dev, v5.8.0, v5.8.11, v5.8.12, v5.8.14, v5.8.15, v5.8.17, v5.8.18, v5.8.19, v5.8.2, v5.8.20, v5.8.22, v5.8.24, v5.8.27, v5.8.28, v5.8.29, v5.8.3, v5.8.30, v5.8.31, v5.8.32, v5.8.33, v5.8.34, v5.8.35, v5.8.36, v5.8.4, v5.8.8, v5.8.9].
- arcanedev/support 4.5.0 requires illuminate/support ~5.8.0 -> satisfiable by laravel/framework[v5.8.38], illuminate/support[5.8.x-dev, v5.8.0, v5.8.11, v5.8.12, v5.8.14, v5.8.15, v5.8.17, v5.8.18, v5.8.19, v5.8.2, v5.8.20, v5.8.22, v5.8.24, v5.8.27, v5.8.28, v5.8.29, v5.8.3, v5.8.30, v5.8.31, v5.8.32, v5.8.33, v5.8.34, v5.8.35, v5.8.36, v5.8.4, v5.8.8, v5.8.9].
- Can only install one of: laravel/framework[6.x-dev, v5.8.38].
- don't install illuminate/support 5.8.x-dev|don't install laravel/framework 6.x-dev
- don't install illuminate/support v5.8.9|don't install laravel/framework 6.x-dev
- Installation request for laravel/framework ^6.0 -> satisfiable by laravel/framework[6.x-dev, v6.0.0, v6.0.1, v6.0.2, v6.0.3, v6.0.4, v6.1.0, v6.10.0, v6.10.1, v6.11.0, v6.12.0, v6.13.0, v6.13.1, v6.14.0, v6.15.0, v6.15.1, v6.16.0, v6.17.0, v6.17.1, v6.18.0, v6.18.1, v6.18.10, v6.18.11, v6.18.12, v6.18.13, v6.18.14, v6.18.15, v6.18.16, v6.18.17, v6.18.18, v6.18.19, v6.18.2, v6.18.20, v6.18.21, v6.18.22, v6.18.23, v6.18.24, v6.18.25, v6.18.26, v6.18.27, v6.18.28, v6.18.29, v6.18.3, v6.18.30, v6.18.31, v6.18.4, v6.18.5, v6.18.6, v6.18.7, v6.18.8, v6.18.9, v6.2.0, v6.3.0, v6.4.0, v6.4.1, v6.5.0, v6.5.1, v6.5.2, v6.6.0, v6.6.1, v6.6.2, v6.7.0, v6.8.0, v6.9.0].
- Installation request for arcanedev/support ~4.5 -> satisfiable by arcanedev/support[4.5.0].
The composer.json
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"require": {
"php": "^7.2",
"laravel/framework": "^6.0",
"fideloper/proxy": "^4.0",
"guzzlehttp/guzzle": "^6.3",
"illuminate/support": "~5.8.0|^6.0",
"intervention/image": "^2.4",
"laravel/tinker": "^1.0",
"spatie/laravel-permission": "^3.0"
},
"require-dev": {
"barryvdh/laravel-ide-helper": "^2.6",
"beyondcode/laravel-dump-server": "^1.0",
"filp/whoops": "^2.0",
"fzaninotto/faker": "^1.4",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^2.0",
"phpunit/phpunit": "^7.0",
"barryvdh/laravel-debugbar": "^3.2",
"arcanedev/log-viewer": "^4.7",
"arcanedev/support": "~4.5"
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"autoload": {
"psr-4": {
"App\\": "app/"
},
"classmap": [
"database/seeds",
"database/factories"
]
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"#php artisan package:discover --ansi"
],
"post-root-package-install": [
"#php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"#php artisan key:generate --ansi"
]
}
}
Just have a look at the error message you've shared: your configuration requires arcanedev/support with the version constraint ~4.5. By peeking into the version list of that package, you can see that there is only one version that can be used, which is 4.5.0, and this package requires illuminate/support with the version constraint ~5.8.0. Obviously, this excludes any later versions of Laravel.
By also updating arcanedev/support to some later version (^5.0 should be fine), you are able to update Laravel. Packagist can help you to inspect the constraints for different versions of that package.

How to setup Sentry-cli source maps with react-native

Introduction
Hi, I'm trying to get Sentry to recognise our sourcemaps in a react-native project, but I can't get it working.
The artifacts are uploading - I can see them in the WebUI, but the events lack context/mapping:
Question
Can anyone see any problems in my setup?
Thanks!
 Background
Assumptions
uploading release artifacts, then deleting artifacts from web ui, then re-uploading new artifacts is valid
"abs_path": "app:///index.bundle", requires the bundled js needs to be renamed to index.bundle
That fact that all events have a processing error: Discarded invalid parameter 'dist' should not effect sourcemaps
Once everything lines up, all my historical events for the release will benefit from the uploaded files/sourcemaps
Xcode build phase
During the XCode build phase we already bundle the DSym.
In this script, I'm trying to pull out the bundled js and sourcemap, and uploading it.
Script
#!/bin/bash
# WARNING: Run directly from Xcode
# For testing of Xcode bundling/sentry locally, set to "true"
DEBUG_FORCE_BUNDLING="true"
printf "Xcode: Bundle react-native and upload to Sentry"
source ../scripts/xcode/utils/node_activate.sh
# Create bundle and sourcemap
export NODE_BINARY=node
export SENTRY_PROPERTIES=sentry.properties
DEST=$CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH
export EXTRA_PACKAGER_ARGS="--sourcemap-output $DEST/main.bundle.map.js";
if [ "${CONFIGURATION}" = "Release" ]; then
FORCE_BUNDLING="$DEBUG_FORCE_BUNDLING" \
../node_modules/#sentry/cli/sentry-cli react-native xcode \
../node_modules/react-native/scripts/react-native-xcode.sh
else
FORCE_BUNDLING="$DEBUG_FORCE_BUNDLING" \
../node_modules/#sentry/cli/sentry-cli react-native xcode \
../node_modules/react-native/scripts/react-native-xcode.sh
fi
# Copy bundle & sourcemap
mkdir -p ../.xcodebuild
cp $DEST/main.jsbundle ../.xcodebuild/index.bundle # rename?
cp $DEST/main.bundle.map.js ../.xcodebuild
echo "Size of file $(wc -c ../.xcodebuild/index.bundle)" # RENAME!?
echo "Size of sourcemap $(wc -c ../.xcodebuild/main.bundle.map.js)"
# Upload sentry release
# https://docs.sentry.io/cli/releases/#creating-releases
APP_IDENTIFIER="com.mycompany.app"
VERSION="1.4.21"
RELEASE_NAME="$APP_IDENTIFIER-$VERSION"
DISTRIBUTION_NAME="2400"
function sentry_release {
npx sentry-cli releases \
files $RELEASE_NAME \
$1 $2 $3
--dist $DISTRIBUTION_NAME \
--strip-prefix ".build" \
--ignore node_modules \
--rewrite "$(pwd)"
}
sentry_release upload ../.xcodebuild/index.bundle '~/index.bundle'
echo "sentry_release upload"
sentry_release upload-sourcemaps ../.xcodebuild/main.bundle.map.js
echo "sentry_release upload-sourcemaps"
echo `date`
echo "DONE"
Note: The important bit of node_modules/react-native/scripts/react-native-xcode.sh is:
BUNDLE_FILE="$DEST/main.jsbundle"
echo "BUNDLE_FILE: $BUNDLE_FILE" > ~/bh/react-native-native/bundle.log
"$NODE_BINARY" $NODE_ARGS "$CLI_PATH" $BUNDLE_COMMAND \
$CONFIG_ARG \
--entry-file "$ENTRY_FILE" \
--platform ios \
--dev $DEV \
--reset-cache \
--bundle-output "$BUNDLE_FILE" \
--assets-dest "$DEST" \
$EXTRA_PACKAGER_ARGS
Script output
Xcode: Upload Debug Symbols to SentryNow using node v11.11.0 (npm v6.7.0)
FORCE_BUNDLING enabled; continuing to bundle.
warning: the transform cache was reset.
Loading dependency graph, done.
info Writing bundle output to:, /Users/me/Library/Developer/Xcode/DerivedData/TheApp-cvfhlrosjrphnjdcngyqxnlmjjbb/Build/Products/Debug-iphonesimulator/TheApp.app/main.jsbundle
info Writing sourcemap output to:, /Users/me/Library/Developer/Xcode/DerivedData/TheApp-cvfhlrosjrphnjdcngyqxnlmjjbb/Build/Products/Debug-iphonesimulator/TheApp.app/main.bundle.map.js
info Done writing bundle output
info Done writing sourcemap output
info Copying 109 asset files
info Done copying assets
Size of file 8477623 ../.xcodebuild/index.bundle
Size of sourcemap 15378754 ../.xcodebuild/main.bundle.map.js
A 560eaee15f0c1ccb5a57b68b5dc1b4944cff84d2 (8477623 bytes)
sentry_release upload
> Analyzing 1 sources
> Adding source map references
> Uploading source maps for release com.mycompany.app-1.4.21
Source Map Upload Report
Source Maps
~/main.bundle.map.js
sentry_release upload-sourcemaps
Fri May 3 15:50:26 BST 2019
DONE
Sentry event JSON
Trimmed some breadcrumbs/callstack:
// 20190503154011
// https://sentry.mycompany.com/mycompany/react-native-app/issues/4205/events/396945/json/
{
"id": "1c754ed7d651445eb48ed79c995073e2",
"project": 11,
"release": "com.mycompany.app-1.4.21",
"platform": "cocoa",
"culprit": "crash(app:///index.bundle)",
"message": "Error Sentry: TEST crash crash(app:///index.bundle)",
"datetime": "2019-05-03T14:32:25.000000Z",
"time_spent": null,
"tags": [
[
"logger",
"javascript"
],
[
"sentry:user",
"id:b5f212b4-9112-4253-86cc-11583ac1945a"
],
[
"sentry:release",
"com.mycompany.app-1.4.21"
],
[
"level",
"fatal"
],
[
"device",
"iPhone9,1"
],
[
"device.family",
"iOS"
],
[
"os",
"iOS 12.1"
],
[
"os.name",
"iOS"
],
[
"os.rooted",
"no"
]
],
"contexts": {
"device": {
"model_id": "simulator",
"family": "iOS",
"simulator": true,
"type": "device",
"storage_size": 499963170816,
"free_memory": 274915328,
"memory_size": 17179869184,
"boot_time": "2019-04-29T07:53:06Z",
"timezone": "GMT+1",
"model": "iPhone9,1",
"usable_memory": 16463810560,
"arch": "x86"
},
"app": {
"app_version": "1.4.21",
"app_name": "MyApp",
"device_app_hash": "<device_app_hash>",
"app_id": "<app_id>",
"app_build": "2400",
"app_start_time": "2019-05-03T14:31:33Z",
"app_identifier": "com.mycompany.app",
"type": "default",
"build_type": "simulator"
},
"os": {
"rooted": false,
"kernel_version": "Darwin Kernel Version 17.7.0: Thu Jun 21 22:53:14 PDT 2018; root:xnu-4570.71.2~1/RELEASE_X86_64",
"version": "12.1",
"build": "17G65",
"type": "os",
"name": "iOS"
}
},
"errors": [
{
"type": "invalid_attribute",
"name": "dist"
}
],
"extra": {
"session:duration": 52129
},
"fingerprint": [
"{{ default }}"
],
"metadata": {
"type": "Error",
"value": "Sentry: TEST crash"
},
"received": 1556893946.0,
"sdk": {
"client_ip": "109.69.86.251",
"version": "0.42.0",
"name": "sentry.javascript.react-native"
},
"sentry.interfaces.Breadcrumbs": {
"values": [
{
"category": "console",
"timestamp": 1556893700.0,
"message": "%c prev state color: #9E9E9E; font-weight: bold [object Object]",
"type": "default"
},
{
"category": "console",
"timestamp": 1556893941.0,
"message": "%c prev state color: #9E9E9E; font-weight: bold [object Object]",
"type": "default"
},
{
"category": "console",
"timestamp": 1556893941.0,
"message": "%c next state color: #4CAF50; font-weight: bold [object Object]",
"type": "default"
},
{
"category": "sentry",
"timestamp": 1556893945.0,
"message": "Error: Sentry: TEST crash",
"type": "default",
"level": "fatal"
}
]
},
"sentry.interfaces.Exception": {
"exc_omitted": null,
"values": [
{
"stacktrace": {
"frames": [
{
"function": "callFunctionReturnFlushedQueue",
"platform": "javascript",
"abs_path": "app:///[native code]",
"in_app": false,
"filename": "app:///[native code]"
},
{
"function": "touchableHandlePress",
"abs_path": "app:///index.bundle",
"in_app": false,
"platform": "javascript",
"lineno": 64988,
"colno": 47,
"filename": "app:///index.bundle"
},
{
"function": "crash",
"abs_path": "app:///index.bundle",
"in_app": false,
"platform": "javascript",
"lineno": 93710,
"colno": 22,
"filename": "app:///index.bundle"
}
],
"has_system_frames": false,
"frames_omitted": null
},
"mechanism": null,
"raw_stacktrace": null,
"value": "Sentry: TEST crash",
"thread_id": 99,
"module": null,
"type": "Error"
}
]
},
"sentry.interfaces.User": {
"id": "b5f212b4-9112-4253-86cc-11583ac1945a"
},
"type": "error",
"version": "7"
}
Artifacts
Web UI
Cut and pasted from Release artifacts page:
Release com.mycompany.app-1.4.21
Artifacts
NAME SIZE
~/index.bundle 8.1 MB
~/main.bundle.map.js 14.7 MB
sourceMappingURL
$ tail -c 50 .xcodebuild/main.jsbundle
//# sourceMappingURL=main.bundle.map.js
After MONTHS, we realised we had to write client code to knit in the Distribution and Release....
const configureSentry = () => {
Sentry.config(config.sentry.dsn).install();
Sentry.setDist(DeviceInfo.getBuildNumber());
Sentry.setRelease(DeviceInfo.getBundleId() + '-' + DeviceInfo.getVersion());
};

Running Mocha tests compiled with Babel in Visual Studio Code

I am using Babel in my Mocha tests. To run the test in terminal I use following command:
mocha --debug --compilers js:babel/register
Then I can use VS Code "Attach" debugging option to attach to the test process. I can set breakpoints and it stops, but because original code is in ES6 VS Code gets confused about line numbers and such.
Is there anyway to make VS Code work with this setup?
My "Attach" config:
{
"name": "Attach",
"type": "node",
// TCP/IP address. Default is "localhost".
"address": "localhost",
// Port to attach to.
"port": 5858,
"sourceMaps": false
}
"sourceMaps": true doesn't make any difference
The project I'm trying to run the test is open source. GitHub repo: https://github.com/mohsen1/yawn-yaml/
I got mocha running with babel locally using this config:
"configurations": [
{
"name": "Debug Mocha",
"type": "node",
"program": "./node_modules/.bin/_mocha",
"stopOnEntry": false,
"args": ["--compilers", "js:babel-register"],
"cwd": ".",
"runtimeExecutable": null,
"runtimeArgs": [
"--nolazy"
],
"env": {
"NODE_ENV": "development"
},
"externalConsole": false,
"sourceMaps": true,
"outDir": null
},
{
"name": "Attach",
"type": "node",
"request": "attach",
"port": 5858
}
]
Which uses the _mocha executable since node is already invoked by Code. Also, make sure you have sourceMaps set to true.

app.user.username in twig returns unable to add global

as per the documentation:
http://symfony.com/doc/current/book/security.html#retrieving-the-user-object
I am trying to use twig to check to see if the user is authenticated
when i put in my twig templates:
{{ app.user.username }}
I get the error
LogicException: Unable to add global "app" as the runtime or the extensions have already been initialized.
EDIT: Please find as per below the composer.json contents
{
"name": "symfony/framework-standard-edition",
"description": "The \"Symfony Standard Edition\" distribution",
"autoload": {
"psr-0": { "": "src/" }
},
"require": {
"php": ">=5.3.3",
"symfony/symfony": "2.1.*",
"doctrine/orm": ">=2.2.3,<2.4-dev",
"doctrine/doctrine-bundle": "1.0.*",
"twig/extensions": "1.0.*#dev",
"symfony/assetic-bundle": "2.1.*",
"symfony/swiftmailer-bundle": "2.1.*",
"symfony/monolog-bundle": "2.1.*",
"sensio/distribution-bundle": "2.1.*",
"sensio/framework-extra-bundle": "2.1.*",
"sensio/generator-bundle": "2.1.*",
"jms/security-extra-bundle": "1.2.*",
"jms/di-extra-bundle": "1.1.*",
"kriswallsmith/assetic": "1.1.*#dev",
"doctrine/data-fixtures": "dev-master",
"doctrine/doctrine-fixtures-bundle": "dev-master"
},
"scripts": {
"post-install-cmd": [
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
],
"post-update-cmd": [
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
]
},
"extra": {
"symfony-app-dir": "app",
"symfony-web-dir": "web"
}
}
Its hard to answer to this question without more details.
First, please notice that there have been such a similar exception in the past, due to a Symfony2.1 bug which has been solved with a recent release: see here for more details.
Then, notice that the error seems to be thrown in addGlobal function of class Twig_Environment. Did you installed such Twig Extension?
Without reading your composer.json, I can suggest to try to:
Clear the cache.
update the code in your composer.json, to avoid the presence of up to date bundles.
Create the composer.phar.
Then compile it to get the composer.phar.
php composer.phar install or php composer.phar update, whatever be your case.
Hope it helps.