1

I'm trying to capture the output of my controller class (yii framework) the following way:

ob_start();
$controller->actionView(4);
ob_end_flush();
assertContains('needlestack', ob_get_contents());
ob_clean();

edit:

Seems it has to do with the use of

To my surprise, the output contains unexecuted PHP code!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="language" content="en" />
    <meta name="description" content="<?=Yii::app()->params['description']?>" />

    <link rel="shortcut icon" href="<?= bu('/images/favicon.png') ?>" />

    <?= $this->renderPartial('//site/_header_js'); ?>

    <link rel="stylesheet" type="text/css" href="/usr/bin/assets/905db112/detailview/styles.css" />
<title><?= CHtml::encode($this->pageTitle); ?></title>

    <link type="text/css" rel="stylesheet" href="<?= bu('css/style.css')?> "/>
    <link type="text/css" rel="stylesheet" href="<?= bu('css/form.css')?> "/>

    <script type="text/javascript" language="javascript" src="<?= bu('js/commonjs.js') ?>"></script>


</head>

<body class="<?= $this->bodyClass ?>">
    <div class="wrapper">
        <!-- Header -->
        <?= $this->renderPartial('//site/_body_header'); ?>

        <?= $content; ?>    
    </div>

    <!-- Footer -->
    <?= $this->renderPartial('//site/_body_footer'); ?>
    <?= $this->renderPartial('//site/_footer_js'); ?>

</body>
</html>

How could PHP echo unexecuted PHP code? How can I get the resulting HTML?

1
  • 1
    I bet the use of ob_get_contents() is a total red herring. Did you try the same thing without it? Commented Jul 18, 2011 at 23:55

2 Answers 2

3

The <?= syntax is short tags, and it looks like they're disabled in your php install. You should set short_open_tag to 1 in the php.ini file, or you can use ini_set( "short_open_tag", 1 ); at the top of your script.

Sign up to request clarification or add additional context in comments.

2 Comments

The short tags work on Apache, just not when I try to capture them using ob_get_contents(). I tried to init_set them to 1 in the unit test file I'm in, but that didn't help :-(
Ah, sry. Apache in XAMPP and phpunit use two different php.inis. It works now :) Thank you very much.
2

Are short open tags enabled? If they aren't, syntaxes like <? ... ?> and <?= ... ?> won't be parsed.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.